-
Notifications
You must be signed in to change notification settings - Fork 2
feat(storage): storage getInfo #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7088fba
28aeb02
9c7dd1e
f93daa2
ce714c4
9a83c48
fd957f5
da3d004
bfb33bd
9db7fed
1af9ad2
35d4853
b30a945
472692b
70944dc
6e34d22
1aee4b9
bf114a8
0b6c347
80b32ab
ced7847
9e87fa3
d779764
ca7c3ab
8aa86d4
f8a9d8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package vela | ||
|
|
||
| import ( | ||
| api "github.com/go-vela/server/api/types" | ||
| ) | ||
|
|
||
| // StorageService handles retrieving storage s3 info from | ||
| // the server methods of the Vela API. | ||
| type StorageService service | ||
|
|
||
| // GetInfo fetches queue info, primarily used during worker onboarding. | ||
| func (svc *StorageService) GetInfo() (*api.StorageInfo, *Response, error) { | ||
| // set the API endpoint path we send the request to | ||
| url := "/api/v1/storage/info" | ||
|
|
||
| // API StorageInfo type we want to return | ||
| t := new(api.StorageInfo) | ||
|
|
||
| // send request using client | ||
| resp, err := svc.client.Call("GET", url, nil, t) | ||
|
|
||
| return t, resp, err | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package vela | ||
|
Check failure on line 1 in vela/storage_test.go
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "github.com/gin-gonic/gin" | ||
|
Check failure on line 5 in vela/storage_test.go
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| api "github.com/go-vela/server/api/types" | ||
| "github.com/go-vela/server/mock/server" | ||
| "github.com/google/go-cmp/cmp" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestStorage_GetInfo_200(t *testing.T) { | ||
| gin.SetMode(gin.TestMode) | ||
|
|
||
| s := httptest.NewServer(server.FakeHandler()) | ||
| c, _ := NewClient(s.URL, "", nil) | ||
| c.Authentication.SetPersonalAccessTokenAuth("token") | ||
| data := []byte(server.StorageInfoResp) | ||
|
Check failure on line 20 in vela/storage_test.go
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| var want *api.StorageInfo | ||
|
|
||
| err := json.Unmarshal(data, &want) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
|
|
||
| // run test | ||
| got, resp, err := c.Storage.GetInfo() | ||
| if err != nil { | ||
| t.Errorf("GetInfo returned err: %v", err) | ||
| } | ||
|
|
||
| if resp.StatusCode != http.StatusCreated { | ||
| t.Errorf("GetInfo returned %v, want %v", resp.StatusCode, http.StatusCreated) | ||
| } | ||
|
|
||
| if diff := cmp.Diff(want, got); diff != "" { | ||
| t.Errorf("GetInfo mismatch (-want +got):\n%s", diff) | ||
| } | ||
| } | ||
|
|
||
| func TestStorage_GetInfo_401(t *testing.T) { | ||
| gin.SetMode(gin.TestMode) | ||
|
|
||
| s := httptest.NewServer(server.FakeHandler()) | ||
| c, _ := NewClient(s.URL, "", nil) | ||
|
|
||
| // run test | ||
| _, resp, err := c.Storage.GetInfo() | ||
| if err == nil { | ||
| t.Errorf("GetInfo should have returned err %v", resp.StatusCode) | ||
| } | ||
| if resp.StatusCode != http.StatusUnauthorized { | ||
|
Check failure on line 55 in vela/storage_test.go
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| t.Errorf("GetInfo returned %v, want %v", resp.StatusCode, http.StatusUnauthorized) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package vela | ||
|
Check failure on line 3 in vela/testattachment.go
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| api "github.com/go-vela/server/api/types" | ||
| ) | ||
|
|
||
| // TestAttachmentService handles retrieving a test attachment from | ||
| // the server methods of the Vela API. | ||
| type TestAttachmentService service | ||
|
|
||
| // Add constructs a test attachment with the provided details. | ||
| func (svc *TestAttachmentService) Add(org, repo string, build int64) (*api.TestAttachment, *Response, error) { | ||
| // set the API endpoint path we send the request to | ||
| u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/reports/testattachment", org, repo, build) | ||
|
|
||
| // API StorageInfo type we want to return | ||
| ta := new(api.TestAttachment) | ||
|
|
||
| // send request using client | ||
| resp, err := svc.client.Call("POST", u, nil, ta) | ||
|
|
||
| return ta, resp, err | ||
| } | ||
|
|
||
| // Update modifies a step with the provided details. | ||
| func (svc *TestAttachmentService) Update(org, repo string, build int64, ta *api.TestAttachment) (*api.TestAttachment, *Response, error) { | ||
| // set the API endpoint path we send the request to | ||
| u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/reports/testattachment", org, repo, build) | ||
|
|
||
| // API Step type we want to return | ||
| _ta := new(api.TestAttachment) | ||
|
|
||
| // send request using client | ||
| resp, err := svc.client.Call("PUT", u, ta, _ta) | ||
|
|
||
| return _ta, resp, err | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package vela | ||
|
Check failure on line 3 in vela/testreport.go
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| api "github.com/go-vela/server/api/types" | ||
| ) | ||
|
|
||
| // TestReportService handles retrieving a test report from | ||
| // the server methods of the Vela API. | ||
| type TestReportService service | ||
|
|
||
| // Add constructs a test report with the provided details. | ||
| func (svc *TestReportService) Add(org, repo string, build int64) (*api.TestReport, *Response, error) { | ||
| // set the API endpoint path we send the request to | ||
| u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/reports/testreport", org, repo, build) | ||
|
|
||
| // API StorageInfo type we want to return | ||
| tr := new(api.TestReport) | ||
|
|
||
| // send request using client | ||
| resp, err := svc.client.Call("POST", u, nil, tr) | ||
|
|
||
| return tr, resp, err | ||
| } | ||
|
|
||
| // Update modifies a step with the provided details. | ||
| func (svc *TestReportService) Update(org, repo string, build int64, tr *api.TestReport) (*api.TestReport, *Response, error) { | ||
| // set the API endpoint path we send the request to | ||
| u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/reports/testreport", org, repo, build) | ||
|
|
||
| // API Step type we want to return | ||
| _tr := new(api.TestReport) | ||
|
|
||
| // send request using client | ||
| resp, err := svc.client.Call("PUT", u, tr, _tr) | ||
|
|
||
| return _tr, resp, err | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Comment should end in a period (godot)