From 4dfd42c3640ae7bc7eb32098ac71feddc5022f67 Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:25:35 -0600 Subject: [PATCH] enhance(log): do not return log library type on add / update (#242) --- go.mod | 2 +- go.sum | 4 +-- vela/log.go | 36 +++++++++----------------- vela/log_test.go | 66 ++++++++++-------------------------------------- 4 files changed, 29 insertions(+), 79 deletions(-) diff --git a/go.mod b/go.mod index fd468f1..94f117b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3b5317b..f2e3dc2 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vela/log.go b/vela/log.go index f154ce4..aab6f29 100644 --- a/vela/log.go +++ b/vela/log.go @@ -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. @@ -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. diff --git a/vela/log_test.go b/vela/log_test.go index e812660..f08125e 100644 --- a/vela/log_test.go +++ b/vela/log_test.go @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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() { @@ -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() { @@ -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() { @@ -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() {