Skip to content

Commit

Permalink
Fix overlooked test.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity committed Jun 27, 2023
1 parent 477edb4 commit 22d0160
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions cmd/kubeapps-apis/plugins/helm/packages/v1alpha1/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,31 @@ func TestGetClient(t *testing.T) {
)).Build()

testCases := []struct {
name string
manager utils.AssetManager
clientGetter clientgetter.ClientProviderInterface
statusCodeClient codes.Code
statusCodeManager connect.Code
name string
manager utils.AssetManager
clientGetter clientgetter.ClientProviderInterface
errorCodeClient connect.Code
errorCodeManager connect.Code
}{
{
name: "it returns internal error status when no manager configured",
manager: nil,
clientGetter: clientGetter,
statusCodeClient: codes.OK,
statusCodeManager: connect.CodeInternal,
name: "it returns internal error status when no manager configured",
manager: nil,
clientGetter: clientGetter,
errorCodeManager: connect.CodeInternal,
},
{
name: "it returns whatever error the clients getter function returns",
manager: manager,
clientGetter: &clientgetter.ClientProvider{ClientsFunc: func(headers http.Header, cluster string) (*clientgetter.ClientGetter, error) {
return nil, status.Errorf(codes.FailedPrecondition, "Bang!")
return nil, connect.NewError(connect.CodeFailedPrecondition, fmt.Errorf("Bang!"))
}},
statusCodeClient: codes.FailedPrecondition,
errorCodeClient: connect.CodeFailedPrecondition,
},
{
name: "it returns failed-precondition when clients getter function is not set",
manager: manager,
clientGetter: &clientgetter.ClientProvider{ClientsFunc: nil},
statusCodeClient: codes.FailedPrecondition,
name: "it returns failed-precondition when clients getter function is not set",
manager: manager,
clientGetter: &clientgetter.ClientProvider{ClientsFunc: nil},
errorCodeClient: connect.CodeFailedPrecondition,
},
{
name: "it returns client without error when configured correctly",
Expand All @@ -137,18 +136,18 @@ func TestGetClient(t *testing.T) {
s := Server{clientGetter: tc.clientGetter, manager: tc.manager}

clientsProvider, errClient := s.clientGetter.GetClients(http.Header{}, "")
if got, want := status.Code(errClient), tc.statusCodeClient; got != want {
t.Errorf("got: %+v, want: %+v", got, want)
if got, want := connect.CodeOf(errClient), tc.errorCodeClient; errClient != nil && got != want {
t.Errorf("got: %+v, want: %+v. err: %+v", got, want, errClient)
}

_, errManager := s.GetManager()

if got, want := connect.CodeOf(errManager), tc.statusCodeManager; errManager != nil && got != want {
if got, want := connect.CodeOf(errManager), tc.errorCodeManager; errManager != nil && got != want {
t.Errorf("got: %+v, want: %+v", got, want)
}

// If there is no error, the client should be a dynamic.Interface implementation.
if tc.statusCodeClient == codes.OK {
if tc.errorCodeClient == 0 {
_, err := clientsProvider.Dynamic()
if err != nil {
t.Errorf("got: nil, want: dynamic.Interface. error %v", err)
Expand Down

0 comments on commit 22d0160

Please sign in to comment.