-
Notifications
You must be signed in to change notification settings - Fork 2
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
implements the project list #16
base: master
Are you sure you want to change the base?
Changes from all commits
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,3 @@ | ||
{ | ||
"go.testFlags": ["-v"] | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package codefresh | ||
|
||
type ( | ||
IProjectAPI interface { | ||
List() ([]*Project, error) | ||
} | ||
project struct { | ||
codefresh *codefresh | ||
} | ||
Project struct { | ||
ProjectName string `json:"projectName"` | ||
PipelineNumber int `json:"pipelineNumber"` | ||
} | ||
getProjectResponse struct { | ||
Total int `json:"limit"` | ||
Projects []*Project `json:"projects"` | ||
} | ||
) | ||
|
||
func newProjectAPI(codefresh *codefresh) IProjectAPI { | ||
return &project{codefresh} | ||
} | ||
|
||
func (p *project) List() ([]*Project, error) { | ||
r := &getProjectResponse{} | ||
|
||
resp, err := p.codefresh.requestAPI(&requestOptions{ | ||
path: "/api/projects", | ||
method: "GET", | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = p.codefresh.decodeResponseInto(resp, r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return r.Projects, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package codefresh | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var clientOptions = ClientOptions{ | ||
Auth: AuthOptions{ | ||
Token: "", | ||
}, | ||
Debug: true, | ||
Host: "https://g.codefresh.io", | ||
} | ||
|
||
func TestProject(t *testing.T) { | ||
|
||
cf := New(&clientOptions) | ||
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. maybe you can use the codefresh/mock/codefresh struct to make this test better? 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. @noam-codefresh is there an example that shows the coddfresh mock structs use. For an API client that should have been code generated, this abstraction is proving to be rather tedious, and hard to follow, it most certainly confuses the compiler |
||
projects, err := cf.Projects().List() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, len(projects), 0) | ||
} |
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.
please do not include this file in the pr
I see the repo doesn't have a .gitignore file - maybe even include one that ignores visual studio code and golang artifacts? (just a suggestion)