Skip to content
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

CLI now shows list of users on console #304

Merged
merged 8 commits into from
Nov 11, 2024
Merged

CLI now shows list of users on console #304

merged 8 commits into from
Nov 11, 2024

Conversation

aashir21
Copy link
Contributor

@aashir21 aashir21 commented Oct 31, 2024

@galasa-team
Copy link

Build successful

Copy link
Member

@eamansour eamansour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved subject to comments being resolved :)

Comment on lines +18 to +103
func NewUsersServletMock(t *testing.T, state string) *httptest.Server {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mockUsersServlet(t, w, r, state)
}))
return server
}

if !strings.Contains(r.URL.Path, "/users") {
t.Errorf("Expected to request '/users', got: %s", r.URL.Path)
}
if r.Header.Get("Accept") != "application/json" {
t.Errorf("Expected Accept: application/json header, got: %s", r.Header.Get("Accept"))
func mockUsersServlet(t *testing.T, writer http.ResponseWriter, request *http.Request, state string) {
writer.Header().Set("Content-Type", "application/json")
var statusCode int
var body string
statusCode = 200
if state == "populated" {
body = `
[
{
"url": "http://localhost:8080/users/d2055afbc0ae6e513fa9b23c1a000d9f",
"login-id": "test-user",
"id": "d2055afbc0ae6e513fa9b23c1a000d9f",
"clients": [
{
"last-login": "2024-10-28T14:54:49.546029Z",
"client-name": "web-ui"
}
]
},
{
"url": "http://localhost:8080/users/d2055afbc0ae6e513fa9b23c1a000d9f",
"login-id": "test-user2",
"id": "d2055afbc0ae6e513fa9b23c1a000d9f",
"clients": [
{
"last-login": "2024-10-28T14:54:49.546029Z",
"client-name": "web-ui"
}
]
},
{
"url": "http://localhost:8080/users/d2055afbc0ae6e513fa9b23c1a000d9f",
"login-id": "test-user3",
"id": "d2055afbc0ae6e513fa9b23c1a000d9f",
"clients": [
{
"last-login": "2024-10-28T14:54:49.546029Z",
"client-name": "web-ui"
},
{
"last-login": "2024-10-28T15:32:49.546029Z",
"client-name": "rest-api"
}
]
}
]
`
} else if state == "empty" {
body = `{
[]
}`
} else if state == "missingLoginIdFlag" {
statusCode = 400
body = `{"error_code": 1155,"error_message": "GAL1155E: The id provided by the --login-id field cannot be an empty string."}`
} else if state == "invalidLoginIdFlag" {
statusCode = 400
body = `{"error_code": 1157,"error_message": "GAL1157E: '%s' is not supported as a valid value. Valid value should not contain spaces. A value of 'admin' is valid but 'galasa admin' is not."}`
} else if state == "populatedByLoginId" {
body = `
[
{
"url": "http://localhost:8080/users/d2055afbc0ae6e513fa9b23c1a000d9f",
"login-id": "test-user",
"id": "d2055afbc0ae6e513fa9b23c1a000d9f",
"clients": [
{
"last-login": "2024-10-28T14:54:49.546029Z",
"client-name": "web-ui"
}
]
}
]
`
} else {
statusCode = 500
body = `{"error_code": 5000,"error_message": "GAL5000E: Error occured when trying to access the endpoint. Report the problem to your Galasa Ecosystem owner."}`
}
w.Header().Set("Content-Type", "application/json")
writer.WriteHeader(statusCode)
writer.Write([]byte(body))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth using HTTP interactions in utils to make responses more specific to the unit tests that use these responses - see runsDelete_test.go for an example as to how this is used in tests.

Also, instead of hard-coding the response JSON, why not create the response objects and marshal them into JSON strings?

@aashir21 aashir21 changed the title CLI now shous list of users on console CLI now shows list of users on console Oct 31, 2024
Signed-off-by: Aashir Siddiqui <[email protected]>
Signed-off-by: Aashir Siddiqui <[email protected]>
Signed-off-by: Aashir Siddiqui <[email protected]>
@galasa-team
Copy link

Build failed, see http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/#/namespaces/galasa-build/pipelineruns/repo-cli-pr-304-68f77 for details. If you are unable to do so, please contact a member of the Galasa team.

Signed-off-by: Aashir Siddiqui <[email protected]>
@galasa-team
Copy link

Build failed, see http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/#/namespaces/galasa-build/pipelineruns/repo-cli-pr-304-26wjd for details. If you are unable to do so, please contact a member of the Galasa team.

@galasa-team
Copy link

Build failed, see http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/#/namespaces/galasa-build/pipelineruns/repo-cli-pr-304-pbmtx for details. If you are unable to do so, please contact a member of the Galasa team.

@galasa-team
Copy link

Build failed, see http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/#/namespaces/galasa-build/pipelineruns/repo-cli-pr-304-mw5sh for details. If you are unable to do so, please contact a member of the Galasa team.

Signed-off-by: Aashir Siddiqui <[email protected]>
@galasa-team
Copy link

Build successful

@aashir21 aashir21 merged commit 4af13f8 into main Nov 11, 2024
6 checks passed
@aashir21 aashir21 deleted the ash-users-cli branch November 11, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants