Skip to content

Commit

Permalink
enhance(log): do not return log library type on add / update (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Jun 9, 2023
1 parent 2b87f24 commit 4dfd42c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 79 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835
github.com/coreos/go-semver v0.3.1
github.com/gin-gonic/gin v1.9.0
github.com/go-vela/server v0.19.3-0.20230608164526-470791d51178
github.com/go-vela/server v0.19.3-0.20230609145007-f8c795f7aa03
github.com/go-vela/types v0.19.3-0.20230523200921-35a0d5fc088c
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/go-cmp v0.5.9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/go-vela/server v0.19.3-0.20230608164526-470791d51178 h1:B8ElmNWhG7T6+eBOQ/JUqFj+TsJ89e6DXWxU/unTMtI=
github.com/go-vela/server v0.19.3-0.20230608164526-470791d51178/go.mod h1:b520o4N7ss4kHATH291Ui1LHwuC0qEgJgg/Jab6yPIQ=
github.com/go-vela/server v0.19.3-0.20230609145007-f8c795f7aa03 h1:Vi1y5faOZ5CaCjCTRfc45z+BpR5JgMpLyIxmy7pSgqE=
github.com/go-vela/server v0.19.3-0.20230609145007-f8c795f7aa03/go.mod h1:b520o4N7ss4kHATH291Ui1LHwuC0qEgJgg/Jab6yPIQ=
github.com/go-vela/types v0.19.3-0.20230523200921-35a0d5fc088c h1:eAApIK5e5MxFF8RzZAFsvTSdwq/AzdUrdhJHOGQ0ILc=
github.com/go-vela/types v0.19.3-0.20230523200921-35a0d5fc088c/go.mod h1:0lsuPfGyVyTWJSi2h3NS6uaEW6DgnFvIzaZu1sXYKrs=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
Expand Down
36 changes: 12 additions & 24 deletions vela/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,25 @@ func (svc *LogService) GetService(org, repo string, build, service int) (*librar
}

// AddService constructs a service log with the provided details.
func (svc *LogService) AddService(org, repo string, build, service int, l *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) AddService(org, repo string, build, service int, l *library.Log) (*Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, build, service)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := svc.client.Call("POST", u, l, v)
resp, err := svc.client.Call("POST", u, l, nil)

return v, resp, err
return resp, err
}

// UpdateService modifies a service log with the provided details.
func (svc *LogService) UpdateService(org, repo string, build, service int, l *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) UpdateService(org, repo string, build, service int, l *library.Log) (*Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, build, service)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := svc.client.Call("PUT", u, l, v)
resp, err := svc.client.Call("PUT", u, l, nil)

return v, resp, err
return resp, err
}

// RemoveService deletes the provided service log.
Expand Down Expand Up @@ -85,31 +79,25 @@ func (svc *LogService) GetStep(org, repo string, build, step int) (*library.Log,
}

// AddStep constructs a step log with the provided details.
func (svc *LogService) AddStep(org, repo string, build, step int, l *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) AddStep(org, repo string, build, step int, l *library.Log) (*Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, build, step)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := svc.client.Call("POST", u, l, v)
resp, err := svc.client.Call("POST", u, l, nil)

return v, resp, err
return resp, err
}

// UpdateStep modifies a step log with the provided details.
func (svc *LogService) UpdateStep(org, repo string, build, step int, l *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) UpdateStep(org, repo string, build, step int, l *library.Log) (*Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, build, step)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := svc.client.Call("PUT", u, l, v)
resp, err := svc.client.Call("PUT", u, l, nil)

return v, resp, err
return resp, err
}

// RemoveStep deletes the provided step log.
Expand Down
66 changes: 14 additions & 52 deletions vela/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestLog_AddService_201(t *testing.T) {
}

// run test
got, resp, err := c.Log.AddService("github", "octocat", 1, 1, &req)
resp, err := c.Log.AddService("github", "octocat", 1, 1, &req)

if err != nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -97,10 +97,6 @@ func TestLog_AddService_201(t *testing.T) {
if resp.StatusCode != http.StatusCreated {
t.Errorf("Log returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Log add is %v, want %v", got, want)
}
}

func TestLog_UpdateService_200(t *testing.T) {
Expand All @@ -110,17 +106,12 @@ func TestLog_UpdateService_200(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

data := []byte(server.LogResp)

var want library.Log
_ = json.Unmarshal(data, &want)

req := library.Log{
Data: Bytes([]byte("Hello, World Manny")),
}

// run test
got, resp, err := c.Log.UpdateService("github", "octocat", 1, 1, &req)
resp, err := c.Log.UpdateService("github", "octocat", 1, 1, &req)

if err != nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -129,10 +120,6 @@ func TestLog_UpdateService_200(t *testing.T) {
if resp.StatusCode != http.StatusOK {
t.Errorf("Log returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Log create is %v, want %v", got, want)
}
}

func TestLog_UpdateService_404(t *testing.T) {
Expand All @@ -142,14 +129,12 @@ func TestLog_UpdateService_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.Log{}

req := library.Log{
Data: Bytes([]byte("Hello, World Manny")),
}

// run test
got, resp, err := c.Log.UpdateService("github", "not-found", 1, 0, &req)
resp, err := c.Log.UpdateService("github", "not-found", 1, 0, &req)

if err == nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -158,10 +143,6 @@ func TestLog_UpdateService_404(t *testing.T) {
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Log returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Log get is %v, want %v", got, want)
}
}

func TestLog_RemoveService_200(t *testing.T) {
Expand Down Expand Up @@ -272,7 +253,7 @@ func TestLog_AddStep_201(t *testing.T) {
}

// run test
got, resp, err := c.Log.AddStep("github", "octocat", 1, 1, &req)
resp, err := c.Log.AddStep("github", "octocat", 1, 1, &req)

if err != nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -281,10 +262,6 @@ func TestLog_AddStep_201(t *testing.T) {
if resp.StatusCode != http.StatusCreated {
t.Errorf("Log returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Log add is %v, want %v", got, want)
}
}

func TestLog_UpdateStep_200(t *testing.T) {
Expand All @@ -294,17 +271,12 @@ func TestLog_UpdateStep_200(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

data := []byte(server.LogResp)

var want library.Log
_ = json.Unmarshal(data, &want)

req := library.Log{
Data: Bytes([]byte("Hello, World Manny")),
}

// run test
got, resp, err := c.Log.UpdateStep("github", "octocat", 1, 1, &req)
resp, err := c.Log.UpdateStep("github", "octocat", 1, 1, &req)

if err != nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -313,10 +285,6 @@ func TestLog_UpdateStep_200(t *testing.T) {
if resp.StatusCode != http.StatusOK {
t.Errorf("Log returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Log create is %v, want %v", got, want)
}
}

func TestLog_UpdateStep_404(t *testing.T) {
Expand All @@ -326,14 +294,12 @@ func TestLog_UpdateStep_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.Log{}

req := library.Log{
Data: Bytes([]byte("Hello, World Manny")),
}

// run test
got, resp, err := c.Log.UpdateStep("github", "not-found", 1, 0, &req)
resp, err := c.Log.UpdateStep("github", "not-found", 1, 0, &req)

if err == nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -342,10 +308,6 @@ func TestLog_UpdateStep_404(t *testing.T) {
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Log returned %v, want %v", resp.StatusCode, http.StatusOK)
}

if !reflect.DeepEqual(got, &want) {
t.Errorf("Log get is %v, want %v", got, want)
}
}

func TestLog_RemoveStep_200(t *testing.T) {
Expand Down Expand Up @@ -414,12 +376,12 @@ func ExampleLogService_AddService() {
}

// Create the log in the server
log, resp, err := c.Log.AddService("github", "octocat", 1, 1, &req)
resp, err := c.Log.AddService("github", "octocat", 1, 1, &req)
if err != nil {
fmt.Println(err)
}

fmt.Printf("Received response code %d, for log %+v", resp.StatusCode, log)
fmt.Printf("Received response code %d for log", resp.StatusCode)
}

func ExampleLogService_UpdateService() {
Expand All @@ -434,12 +396,12 @@ func ExampleLogService_UpdateService() {
}

// Update the log in the server
log, resp, err := c.Log.UpdateService("github", "octocat", 1, 1, &req)
resp, err := c.Log.UpdateService("github", "octocat", 1, 1, &req)
if err != nil {
fmt.Println(err)
}

fmt.Printf("Received response code %d, for log %+v", resp.StatusCode, log)
fmt.Printf("Received response code %d, for log", resp.StatusCode)
}

func ExampleLogService_RemoveService() {
Expand Down Expand Up @@ -486,12 +448,12 @@ func ExampleLogService_AddStep() {
}

// Create the log in the server
log, resp, err := c.Log.AddStep("github", "octocat", 1, 1, &req)
resp, err := c.Log.AddStep("github", "octocat", 1, 1, &req)
if err != nil {
fmt.Println(err)
}

fmt.Printf("Received response code %d, for log %+v", resp.StatusCode, log)
fmt.Printf("Received response code %d for log", resp.StatusCode)
}

func ExampleLogService_UpdateStep() {
Expand All @@ -506,12 +468,12 @@ func ExampleLogService_UpdateStep() {
}

// Update the log in the server
log, resp, err := c.Log.UpdateStep("github", "octocat", 1, 1, &req)
resp, err := c.Log.UpdateStep("github", "octocat", 1, 1, &req)
if err != nil {
fmt.Println(err)
}

fmt.Printf("Received response code %d, for log %+v", resp.StatusCode, log)
fmt.Printf("Received response code %d for log", resp.StatusCode)
}

func ExampleLogService_RemoveStep() {
Expand Down

0 comments on commit 4dfd42c

Please sign in to comment.