Skip to content

Commit

Permalink
fix(test): adding logging to HttpLogin function (#8350)
Browse files Browse the repository at this point in the history
## Problem
need logging for identifying flaky test issue with `restore`

## Solution
super verbose logging
  • Loading branch information
skrdgraph authored and joshua-goldstein committed Oct 17, 2022
1 parent e5c263b commit cdedc3b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion testutil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,16 @@ type LoginParams struct {
// and returns the access JWT and refresh JWT extracted from
// the HTTP response
func HttpLogin(params *LoginParams) (*HttpToken, error) {
fmt.Println("HttpLogin: params data ", params)
loginPayload := api.LoginRequest{}
fmt.Println("HttpLogin: login payload at start", loginPayload)
if len(params.RefreshJwt) > 0 {
loginPayload.RefreshToken = params.RefreshJwt
} else {
loginPayload.Userid = params.UserID
loginPayload.Password = params.Passwd
}
fmt.Println("HttpLogin: login payload at end", loginPayload)

login := `mutation login($userId: String, $password: String, $namespace: Int, $refreshToken: String) {
login(userId: $userId, password: $password, namespace: $namespace, refreshToken: $refreshToken) {
Expand All @@ -288,24 +291,28 @@ func HttpLogin(params *LoginParams) (*HttpToken, error) {
if err != nil {
return nil, errors.Wrapf(err, "unable to marshal body")
}
fmt.Println("HttpLogin: body", body)

req, err := http.NewRequest("POST", params.Endpoint, bytes.NewBuffer(body))
if err != nil {
return nil, errors.Wrapf(err, "unable to create request")
}
req.Header.Set("Content-Type", "application/json")
fmt.Println("HttpLogin: req", req)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, errors.Wrapf(err, "login through curl failed")
}
fmt.Println("HttpLogin: resp", resp)
defer resp.Body.Close()

respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrapf(err, "unable to read from response")
}
fmt.Println("HttpLogin: respBody", respBody)
if resp.StatusCode != http.StatusOK {
return nil, errors.New(fmt.Sprintf("got non 200 response from the server with %s ",
string(respBody)))
Expand All @@ -320,6 +327,7 @@ func HttpLogin(params *LoginParams) (*HttpToken, error) {
}
return nil, errors.Wrapf(err, "unable to unmarshal the output to get JWTs")
}
fmt.Println("HttpLogin: outputJson", outputJson)

data, found := outputJson["data"].(map[string]interface{})
if !found {
Expand All @@ -344,7 +352,11 @@ func HttpLogin(params *LoginParams) (*HttpToken, error) {
if !found || newRefreshJwt == "" {
return nil, errors.Errorf("no refresh JWT found in the output")
}

fmt.Println("HttpLogin: http token ", &HttpToken{UserId: params.UserID,
Password: params.Passwd,
AccessJwt: newAccessJwt,
RefreshToken: newRefreshJwt,
})
return &HttpToken{
UserId: params.UserID,
Password: params.Passwd,
Expand Down

0 comments on commit cdedc3b

Please sign in to comment.