Skip to content

Commit

Permalink
Vault: update of LogHttpError method (#117)
Browse files Browse the repository at this point in the history
Vault: update of `LogHttpError` method

Update LogHttpError to receive detailed errors.
Acceptance tests
artem@Artems vault-plugin-secrets-openstack % make functional
Running acceptance tests...
=== RUN   TestPlugin
=== RUN   TestPlugin/TestCloudLifecycle
=== RUN   TestPlugin/TestCloudLifecycle/WriteCloud
=== RUN   TestPlugin/TestCloudLifecycle/ReadCloud
=== RUN   TestPlugin/TestCloudLifecycle/ListClouds
=== RUN   TestPlugin/TestCloudLifecycle/ListClouds/method-LIST
=== PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-LIST
=== RUN   TestPlugin/TestCloudLifecycle/ListClouds/method-GET
=== PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-GET
=== CONT  TestPlugin/TestCloudLifecycle/ListClouds/method-LIST
=== CONT  TestPlugin/TestCloudLifecycle/ListClouds/method-GET
=== RUN   TestPlugin/TestCloudLifecycle/DeleteCloud
=== RUN   TestPlugin/TestCredsLifecycle
=== RUN   TestPlugin/TestCredsLifecycle/root_token
=== RUN   TestPlugin/TestCredsLifecycle/user_token
=== RUN   TestPlugin/TestCredsLifecycle/user_password
=== RUN   TestPlugin/TestInfo
info_test.go:42:
Error Trace:    info_test.go:42
Error:          Should NOT be empty, but was &{    }
Test:           TestPlugin/TestInfo
=== RUN   TestPlugin/TestRoleLifecycle
^CFAIL  github.com/opentelekomcloud/vault-plugin-secrets-openstack/acceptance   17.620s
make: *** [functional] Error 1
artem@Artems-MacBook-Pro vault-plugin-secrets-openstack % make functional
Running acceptance tests...
=== RUN   TestPlugin
=== RUN   TestPlugin/TestCloudLifecycle
=== RUN   TestPlugin/TestCloudLifecycle/WriteCloud
=== RUN   TestPlugin/TestCloudLifecycle/ReadCloud
=== RUN   TestPlugin/TestCloudLifecycle/ListClouds
=== RUN   TestPlugin/TestCloudLifecycle/ListClouds/method-LIST
=== PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-LIST
=== RUN   TestPlugin/TestCloudLifecycle/ListClouds/method-GET
=== PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-GET
=== CONT  TestPlugin/TestCloudLifecycle/ListClouds/method-LIST
=== CONT  TestPlugin/TestCloudLifecycle/ListClouds/method-GET
=== RUN   TestPlugin/TestCloudLifecycle/DeleteCloud
=== RUN   TestPlugin/TestCredsLifecycle
=== RUN   TestPlugin/TestCredsLifecycle/user_token
=== RUN   TestPlugin/TestCredsLifecycle/user_password
=== RUN   TestPlugin/TestCredsLifecycle/root_token
=== RUN   TestPlugin/TestInfo
info_test.go:42:
Error Trace:    info_test.go:42
Error:          Should NOT be empty, but was &{    }
Test:           TestPlugin/TestInfo
=== RUN   TestPlugin/TestRoleLifecycle
=== RUN   TestPlugin/TestRoleLifecycle/WriteRole
=== RUN   TestPlugin/TestRoleLifecycle/ReadRole
=== RUN   TestPlugin/TestRoleLifecycle/ListRoles
=== RUN   TestPlugin/TestRoleLifecycle/ListRoles/method-LIST
=== PAUSE TestPlugin/TestRoleLifecycle/ListRoles/method-LIST
=== RUN   TestPlugin/TestRoleLifecycle/ListRoles/method-GET
=== PAUSE TestPlugin/TestRoleLifecycle/ListRoles/method-GET
=== CONT  TestPlugin/TestRoleLifecycle/ListRoles/method-LIST
=== CONT  TestPlugin/TestRoleLifecycle/ListRoles/method-GET
=== RUN   TestPlugin/TestRoleLifecycle/DeleteRole
=== RUN   TestPlugin/TestRootRotate
rotate_test.go:65: Cloud with name default1 was created
rotate_test.go:68: Cloud with name rr7c was created
plugin_test.go:337: Cloud with name rr7c has been removed
plugin_test.go:337: Cloud with name default1 has been removed
=== RUN   TestPlugin/TestStaticCredsLifecycle
=== RUN   TestPlugin/TestStaticCredsLifecycle/user_password
=== RUN   TestPlugin/TestStaticCredsLifecycle/user_token_project_id
=== RUN   TestPlugin/TestStaticCredsLifecycle/user_token_project_name
=== RUN   TestPlugin/TestStaticRoleLifecycle
=== RUN   TestPlugin/TestStaticRoleLifecycle/WriteRole
=== RUN   TestPlugin/TestStaticRoleLifecycle/ReadRole
=== RUN   TestPlugin/TestStaticRoleLifecycle/ListRoles
=== RUN   TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST
=== PAUSE TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST
=== RUN   TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET
=== PAUSE TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET
=== CONT  TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST
=== CONT  TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET
=== RUN   TestPlugin/TestStaticRoleLifecycle/DeleteRole
--- FAIL: TestPlugin (25.82s)
--- PASS: TestPlugin/TestCloudLifecycle (0.09s)
--- PASS: TestPlugin/TestCloudLifecycle/WriteCloud (0.09s)
--- PASS: TestPlugin/TestCloudLifecycle/ReadCloud (0.00s)
--- PASS: TestPlugin/TestCloudLifecycle/ListClouds (0.00s)
--- PASS: TestPlugin/TestCloudLifecycle/ListClouds/method-LIST (0.00s)
--- PASS: TestPlugin/TestCloudLifecycle/ListClouds/method-GET (0.00s)
--- PASS: TestPlugin/TestCloudLifecycle/DeleteCloud (0.00s)
--- PASS: TestPlugin/TestCredsLifecycle (5.71s)
--- PASS: TestPlugin/TestCredsLifecycle/user_token (3.13s)
--- PASS: TestPlugin/TestCredsLifecycle/user_password (0.93s)
--- PASS: TestPlugin/TestCredsLifecycle/root_token (0.80s)
--- FAIL: TestPlugin/TestInfo (0.00s)
--- PASS: TestPlugin/TestRoleLifecycle (0.63s)
--- PASS: TestPlugin/TestRoleLifecycle/WriteRole (0.62s)
--- PASS: TestPlugin/TestRoleLifecycle/ReadRole (0.00s)
--- PASS: TestPlugin/TestRoleLifecycle/ListRoles (0.00s)
--- PASS: TestPlugin/TestRoleLifecycle/ListRoles/method-LIST (0.00s)
--- PASS: TestPlugin/TestRoleLifecycle/ListRoles/method-GET (0.00s)
--- PASS: TestPlugin/TestRoleLifecycle/DeleteRole (0.00s)
--- PASS: TestPlugin/TestRootRotate (4.51s)
--- PASS: TestPlugin/TestStaticCredsLifecycle (11.94s)
--- PASS: TestPlugin/TestStaticCredsLifecycle/user_password (3.37s)
--- PASS: TestPlugin/TestStaticCredsLifecycle/user_token_project_id (3.74s)
--- PASS: TestPlugin/TestStaticCredsLifecycle/user_token_project_name (3.80s)
--- PASS: TestPlugin/TestStaticRoleLifecycle (2.77s)
--- PASS: TestPlugin/TestStaticRoleLifecycle/WriteRole (1.06s)
--- PASS: TestPlugin/TestStaticRoleLifecycle/ReadRole (0.01s)
--- PASS: TestPlugin/TestStaticRoleLifecycle/ListRoles (0.00s)
--- PASS: TestPlugin/TestStaticRoleLifecycle/ListRoles/method-GET (0.00s)
--- PASS: TestPlugin/TestStaticRoleLifecycle/ListRoles/method-LIST (0.00s)
--- PASS: TestPlugin/TestStaticRoleLifecycle/DeleteRole (0.01s)
FAIL
FAIL    github.com/opentelekomcloud/vault-plugin-secrets-openstack/acceptance   26.416s
FAIL
make: *** [functional] Error 1

Reviewed-by: Anton Sidelnikov
Reviewed-by: Aloento
  • Loading branch information
artem-lifshits authored Nov 9, 2022
1 parent 4ad93e0 commit c505d76
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions openstack/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,33 @@ func sliceSubtraction(a, b []string) (diff []string) {
}

func LogHttpError(err error) error {
if httpErr, ok := err.(golangsdk.ErrUnexpectedResponseCode); ok {
return fmt.Errorf("response: %s\n %s", httpErr.Error(), httpErr.Body)
switch httpErr := err.(type) {
case golangsdk.ErrDefault400:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault401:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault403:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault404:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault405:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault408:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault409:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault429:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault500:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault502:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault503:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrDefault504:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
case golangsdk.ErrUnexpectedResponseCode:
return fmt.Errorf("%s\n %s", httpErr.Error(), httpErr.Body)
}
return err
}

0 comments on commit c505d76

Please sign in to comment.