diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-05-02 14:34:35 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-05-02 14:34:35 +0200 |
| commit | 466450f0c47bdc614e66326d90e5fc6fb56ae732 (patch) | |
| tree | a01518a58d50d2f8449d37dadecc40e35c9f1fe1 /state_test.go | |
| parent | a2a8efdcaad3d9b1852b1367a7cd7e8c5860cecf (diff) | |
Refactor: Wrap most errors in a custom type
Diffstat (limited to 'state_test.go')
| -rw-r--r-- | state_test.go | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/state_test.go b/state_test.go index 4320a6d..c6e33e0 100644 --- a/state_test.go +++ b/state_test.go @@ -84,15 +84,43 @@ func test_connect_oauth_parameter(t *testing.T, parameters internal.URLParameter }, false) _, configErr := state.ConnectInstituteAccess(serverURI) - if !errors.As(configErr, expectedErr) { - t.Errorf("error %T = %v, wantErr %T", configErr, configErr, expectedErr) + var stateErr *StateConnectError + var loginErr *internal.OAuthLoginError + var finishErr *internal.OAuthFinishError + + // We go through the chain of errors by unwrapping them one by one + + // First ensure we get a state connect error + if !errors.As(configErr, &stateErr) { + t.Errorf("error %T = %v, wantErr %T", configErr, configErr, stateErr) + } + + // Then ensure we get a login error + gotLoginErr := stateErr.Err + + if !errors.As(gotLoginErr, &loginErr) { + t.Errorf("error %T = %v, wantErr %T", gotLoginErr, gotLoginErr, loginErr) + } + + // Then ensure we get a finish error + gotFinishErr := loginErr.Err + + if !errors.As(gotFinishErr, &finishErr) { + t.Errorf("error %T = %v, wantErr %T", gotFinishErr, gotFinishErr, finishErr) + } + + // Then ensure we get the expected inner error + gotExpectedErr := finishErr.Err + + if !errors.As(gotExpectedErr, expectedErr) { + t.Errorf("error %T = %v, wantErr %T", gotExpectedErr, gotExpectedErr, expectedErr) } } func Test_connect_oauth_parameters(t *testing.T) { var ( - failedCallbackParameterError *internal.OAuthFailedCallbackParameterError - failedCallbackStateMatchError *internal.OAuthFailedCallbackStateMatchError + failedCallbackParameterError *internal.OAuthCallbackParameterError + failedCallbackStateMatchError *internal.OAuthCallbackStateMatchError ) tests := []struct { |
