Skip to content

Commit

Permalink
enhance spacelister get tests
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Ilario <[email protected]>
  • Loading branch information
filariow committed Jul 15, 2024
1 parent 76e43eb commit a85b104
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions pkg/proxy/handlers/spacelister_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func TestSpaceListerGetPublicViewerEnabled(t *testing.T) {
}
}

func TestSpaceListerGetWithBindingsCommunityEnabled(t *testing.T) {
func TestSpaceListerGetWithBindingsWithPublicViewerEnabled(t *testing.T) {

fakeSignupService := fake.NewSignupService(
newSignup("batman", "batman.space", true),
Expand Down Expand Up @@ -893,12 +893,9 @@ func TestSpaceListerGetWithBindingsCommunityEnabled(t *testing.T) {
)

tests := map[string]struct {
username string
expectedErr string
workspaceRequest string
expectedWorkspace *toolchainv1alpha1.Workspace
overrideInformerFunc func() service.InformerService
overrideSignupFunc func(ctx *gin.Context, userID, username string, checkUserSignupComplete bool) (*signup.Signup, error)
username string
workspaceRequest string
expectedWorkspace *toolchainv1alpha1.Workspace
}{
"robin can get robin workspace": {
username: "robin.space",
Expand All @@ -924,7 +921,6 @@ func TestSpaceListerGetWithBindingsCommunityEnabled(t *testing.T) {
username: "robin.space",
workspaceRequest: "batman",
expectedWorkspace: nil,
expectedErr: "",
},
}

Expand All @@ -933,13 +929,7 @@ func TestSpaceListerGetWithBindingsCommunityEnabled(t *testing.T) {
t.Run(k, func(t *testing.T) {
// given
signupProvider := fakeSignupService.GetSignupFromInformer
if tc.overrideSignupFunc != nil {
signupProvider = tc.overrideSignupFunc
}
informerFunc := fake.GetInformerService(fakeClient)
if tc.overrideInformerFunc != nil {
informerFunc = tc.overrideInformerFunc
}

proxyMetrics := metrics.NewProxyMetrics(prometheus.NewRegistry())
s := &handlers.SpaceLister{
Expand Down Expand Up @@ -973,18 +963,8 @@ func TestSpaceListerGetWithBindingsCommunityEnabled(t *testing.T) {
wrk, err := handlers.GetUserWorkspaceWithBindings(ctx, s, tc.workspaceRequest, getMembersFuncMock)

// then
if tc.expectedErr != "" {
// error case
require.Error(t, err, tc.expectedErr)
} else {
require.NoError(t, err)
}

if tc.expectedWorkspace != nil {
require.Equal(t, tc.expectedWorkspace, wrk)
} else {
require.Nil(t, wrk) // user is not authorized to get this workspace
}
require.NoError(t, err)
require.Equal(t, tc.expectedWorkspace, wrk)
})
}
}

0 comments on commit a85b104

Please sign in to comment.