Skip to content

Commit

Permalink
feat: build executable sdk implementation (#250)
Browse files Browse the repository at this point in the history
* feat:build executable sdk implementation

* feat: build executable sdk implementation test

* feat: build executable sdk implementation test

* feat: build executable sdk implementation fix comment

---------

Co-authored-by: Claire.Nicholas <[email protected]>
  • Loading branch information
claire1618 and Claire.Nicholas authored Aug 24, 2023
1 parent 9678a2f commit 0b0212b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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/types 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
github.com/google/go-querystring v1.1.0
Expand All @@ -27,7 +27,6 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhD
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -29,10 +28,10 @@ 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 h1:TsAhCj3wqm4kxfq9M6J8+3MmBKlDeJoTr4UGknT9yQw=
github.com/go-vela/server v0.20.1/go.mod h1:M4rSAg8arMhIQYXQpc/ZmMbNW73ur8yE88klMk0Dq9w=
github.com/go-vela/types v0.20.1 h1:hHAX0Iij2J7UZ9f3SlXbwNy481CjKzU9CBfkiLuysVE=
github.com/go-vela/types v0.20.1/go.mod h1:AXO4oQSygOBQ02fPapsKjQHkx2aQO3zTu7clpvVbXBY=
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/types v0.20.2-0.20230822144153-14b37585731d h1:ag6trc3Ev+7hzifeWy0M9rHHjrO9nFCYgW8dlKdZ4j4=
github.com/go-vela/types v0.20.2-0.20230822144153-14b37585731d/go.mod h1:AXO4oQSygOBQ02fPapsKjQHkx2aQO3zTu7clpvVbXBY=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
Expand All @@ -53,7 +52,6 @@ github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZX
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
Expand Down
14 changes: 14 additions & 0 deletions vela/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ func (svc *BuildService) Get(org, repo string, build int) (*library.Build, *Resp
return v, resp, err
}

// GetBuildExecutable returns the executable for the provided build.
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.BuildExecutable)

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

return v, resp, err
}

// GetAll returns a list of all builds.
func (svc *BuildService) GetAll(org, repo string, opt *BuildListOptions) (*[]library.Build, *Response, error) {
// set the API endpoint path we send the request to
Expand Down
53 changes: 53 additions & 0 deletions vela/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,59 @@ func TestBuild_Get_404(t *testing.T) {
}
}

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

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

data := []byte(server.BuildExecutableResp)

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

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

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

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

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

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 0b0212b

Please sign in to comment.