-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
Signed-off-by: Aashir Siddiqui <[email protected]>
Build successful |
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.
Approved subject to comments being resolved :)
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)) |
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.
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?
Signed-off-by: Aashir Siddiqui <[email protected]>
Signed-off-by: Aashir Siddiqui <[email protected]>
Signed-off-by: Aashir Siddiqui <[email protected]>
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]>
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. |
Signed-off-by: Aashir Siddiqui <[email protected]>
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. |
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]>
Build successful |
Why?
Signed-off-by: Aashir Siddiqui [email protected]