Skip to content

Commit

Permalink
feat: build executable sdk implementation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Aug 23, 2023
1 parent a0b5292 commit 4b4c4a0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 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.1
github.com/go-vela/server v0.20.1
github.com/go-vela/server v0.20.1-0.20230823183045-5f6be5c458d8
github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/google/go-cmp v0.5.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-vela/server v0.20.1-0.20230823183045-5f6be5c458d8 h1:XcCcQa9XafEH2/A+I9WSHNoDgJNhL/0dlyrIrAxOFEM=
github.com/go-vela/server v0.20.1-0.20230823183045-5f6be5c458d8/go.mod h1:lSpD7Ws6GCjqlUf+tJgmzpUTGdhW/jwif4qloEpd0kA=
github.com/go-vela/server v0.20.1 h1:TsAhCj3wqm4kxfq9M6J8+3MmBKlDeJoTr4UGknT9yQw=
github.com/go-vela/server v0.20.1/go.mod h1:M4rSAg8arMhIQYXQpc/ZmMbNW73ur8yE88klMk0Dq9w=
github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d h1:ag6trc3Ev+7hzifeWy0M9rHHjrO9nFCYgW8dlKdZ4j4=
Expand Down
4 changes: 2 additions & 2 deletions vela/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (svc *BuildService) Get(org, repo string, build int) (*library.Build, *Resp
}

// Get returns the provided build executable.
func (svc *BuildService) GetBuildExecutable(org, repo string, build int) (*library.Build, *Response, error) {
func (svc *BuildService) GetBuildExecutable(org, repo string, build int) (*library.BuildExecutable, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/executable", org, repo, build)

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

// send request using client
resp, err := svc.client.Call("GET", u, nil, v)
Expand Down
31 changes: 28 additions & 3 deletions vela/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func TestBuildExecutable_Get_200(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

data := []byte(server.BuildResp)
data := []byte(server.BuildExecutableResp)

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

// run test
got, resp, err := c.Build.Get("github", "octocat", 1)
got, resp, err := c.Build.GetBuildExecutable("github", "octocat", 1)

if err != nil {
t.Errorf("New returned err: %v", err)
Expand All @@ -100,6 +100,31 @@ func TestBuildExecutable_Get_200(t *testing.T) {
}
}

func TestBuildExecutable_Get_500(t *testing.T) {
// setup context
gin.SetMode(gin.TestMode)

s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

want := library.BuildExecutable{}

// run test
got, resp, err := c.Build.GetBuildExecutable("github", "octocat", 0)

if err == nil {
t.Errorf("New returned err: %v", err)
}

if resp.StatusCode != http.StatusInternalServerError {
t.Errorf("Build returned %v, want %v", resp.StatusCode, http.StatusInternalServerError)
}

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

func TestBuild_GetAll_200(t *testing.T) {
// setup context
gin.SetMode(gin.TestMode)
Expand Down

0 comments on commit 4b4c4a0

Please sign in to comment.