Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused RestClient param #10

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("update is successful", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -75,9 +75,9 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("UserSignup should not be updated", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -93,9 +93,9 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("change UserSignup func returns error", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -111,12 +111,12 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("get of UserSignup fails", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
fakeClient.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error {
return fmt.Errorf("some error")
}
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -131,12 +131,12 @@ func TestPatchUserSignup(t *testing.T) {
t.Run("update of UserSignup fails", func(t *testing.T) {
//given
userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
fakeClient.MockPatch = func(ctx context.Context, obj runtimeclient.Object, patch runtimeclient.Patch, opts ...runtimeclient.PatchOption) error {
return fmt.Errorf("some error")
}
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -157,8 +157,7 @@ func TestPatchUserSignup(t *testing.T) {
newClient := func(_, _ string) (runtimeclient.Client, error) {
return nil, fmt.Errorf("some error")
}
newRESTClient := client.DefaultNewRESTClient
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand All @@ -177,9 +176,9 @@ func TestUpdateUserSignupLacksPermissions(t *testing.T) {
SetFileConfig(t, Host(NoToken()))

userSignup := NewUserSignup()
newClient, newRESTClient, fakeClient := NewFakeClients(t, userSignup)
newClient, fakeClient := NewFakeClients(t, userSignup)
term := NewFakeTerminal()
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := client.PatchUserSignup(ctx, userSignup.Name, func(signup *toolchainv1alpha1.UserSignup) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/add_space_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
term := ioutils.NewTerminal(cmd.InOrStdin, cmd.OutOrStdout)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient, client.DefaultNewRESTClient)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient)

Check warning on line 31 in pkg/cmd/add_space_users.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/add_space_users.go#L31

Added line #L31 was not covered by tests

return AddSpaceUsers(ctx, spaceName, role, users)
},
Expand Down
38 changes: 19 additions & 19 deletions pkg/cmd/add_space_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func TestAddSpaceUsers(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
mur2 := masteruserrecord.NewMasterUserRecord(t, "bob", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)
newClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("Y")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "admin", []string{"alice", "bob"})
Expand All @@ -47,11 +47,11 @@ func TestAddSpaceUsers(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
mur2 := masteruserrecord.NewMasterUserRecord(t, "bob", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)
newClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("Y")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "viewer", []string{"alice", "bob"})
Expand All @@ -69,11 +69,11 @@ func TestAddSpaceUsers(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
mur2 := masteruserrecord.NewMasterUserRecord(t, "bob", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)
newClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("N")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "admin", []string{"alice", "bob"})
Expand All @@ -91,11 +91,11 @@ func TestAddSpaceUsers(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
mur2 := masteruserrecord.NewMasterUserRecord(t, "bob", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := NewFakeClients(t, mur1, mur2) // no space
newClient, fakeClient := NewFakeClients(t, mur1, mur2) // no space

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("N")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "admin", []string{"alice", "bob"})
Expand All @@ -111,11 +111,11 @@ func TestAddSpaceUsers(t *testing.T) {

t.Run("when first mur not found", func(t *testing.T) {
// given
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t) // no murs
newClient, fakeClient := initAddSpaceUsersTest(t) // no murs

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("N")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "admin", []string{"alice", "bob"})
Expand All @@ -132,11 +132,11 @@ func TestAddSpaceUsers(t *testing.T) {
t.Run("when second mur not found", func(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t, mur1) // mur2 missing
newClient, fakeClient := initAddSpaceUsersTest(t, mur1) // mur2 missing

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("N")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "admin", []string{"alice", "bob"})
Expand All @@ -153,11 +153,11 @@ func TestAddSpaceUsers(t *testing.T) {
t.Run("when role is invalid", func(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t, mur1) // mur2 missing
newClient, fakeClient := initAddSpaceUsersTest(t, mur1) // mur2 missing

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("N")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "badrole", []string{"alice", "bob"}) // invalid role
Expand All @@ -177,14 +177,14 @@ func TestAddSpaceUsers(t *testing.T) {
// given
mur1 := masteruserrecord.NewMasterUserRecord(t, "alice", masteruserrecord.TierName("deactivate30"))
mur2 := masteruserrecord.NewMasterUserRecord(t, "bob", masteruserrecord.TierName("deactivate30"))
newClient, newRESTClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)
newClient, fakeClient := initAddSpaceUsersTest(t, mur1, mur2)
fakeClient.MockGet = func(ctx context.Context, key runtimeclient.ObjectKey, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error {
return fmt.Errorf("client error")
}

SetFileConfig(t, Host())
term := NewFakeTerminalWithResponse("Y")
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)

// when
err := cmd.AddSpaceUsers(ctx, "testspace", "admin", []string{"alice", "bob"})
Expand All @@ -199,7 +199,7 @@ func TestAddSpaceUsers(t *testing.T) {
})
}

func initAddSpaceUsersTest(t *testing.T, murs ...*toolchainv1alpha1.MasterUserRecord) (clicontext.NewClientFunc, clicontext.NewRESTClientFunc, *test.FakeClient) {
func initAddSpaceUsersTest(t *testing.T, murs ...*toolchainv1alpha1.MasterUserRecord) (clicontext.NewClientFunc, *test.FakeClient) {
space := newSpace()
nsTemplateTier := newNSTemplateTier("base")
roles := make(map[string]toolchainv1alpha1.NSTemplateTierSpaceRole)
Expand All @@ -214,8 +214,8 @@ func initAddSpaceUsersTest(t *testing.T, murs ...*toolchainv1alpha1.MasterUserRe
for _, mur := range murs {
objs = append(objs, mur)
}
newClient, newRESTClient, fakeClient := NewFakeClients(t, objs...)
return newClient, newRESTClient, fakeClient
newClient, fakeClient := NewFakeClients(t, objs...)
return newClient, fakeClient
}

func assertSpaceBindings(t *testing.T, fakeClient *test.FakeClient, expectedMurs []string, expectedRole string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/adm/register_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Long: `Downloads the 'add-cluster.sh' script from the 'toolchain-cicd' repo and calls it twice: once to register the Host cluster in the Member cluster and once to register the Member cluster in the host cluster.`,
RunE: func(cmd *cobra.Command, args []string) error {
term := ioutils.NewTerminal(cmd.InOrStdin, cmd.OutOrStdout)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient, client.DefaultNewRESTClient)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient)

Check warning on line 40 in pkg/cmd/adm/register_member.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/register_member.go#L40

Added line #L40 was not covered by tests
newCommand := func(name string, args ...string) *exec.Cmd {
return exec.Command(name, args...)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/cmd/adm/register_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func TestRegisterMember(t *testing.T) {
t.Run("When automatic approval is enabled", func(t *testing.T) {
term := NewFakeTerminalWithResponse("Y")
toolchainConfig := config.NewToolchainConfigObj(t, config.AutomaticApproval().Enabled(true))
newClient, newRESTClient, fakeClient := NewFakeClients(t, toolchainConfig, deployment)
newClient, fakeClient := NewFakeClients(t, toolchainConfig, deployment)
numberOfUpdateCalls := 0
fakeClient.MockUpdate = whenDeploymentThenUpdated(t, fakeClient, hostDeploymentName, 1, &numberOfUpdateCalls)
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)
counter = 0

// when
Expand Down Expand Up @@ -87,14 +87,14 @@ func TestRegisterMember(t *testing.T) {

t.Run("When toolchainConfig is not present", func(t *testing.T) {
term := NewFakeTerminalWithResponse("Y")
newClient, newRESTClient, fakeClient := NewFakeClients(t, deployment)
newClient, fakeClient := NewFakeClients(t, deployment)
fakeClient.MockUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
if _, ok := obj.(*toolchainv1alpha1.ToolchainConfig); ok {
return fmt.Errorf("should not be called")
}
return fakeClient.Client.Update(ctx, obj, opts...)
}
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)
counter = 0

// when
Expand All @@ -113,14 +113,14 @@ func TestRegisterMember(t *testing.T) {
t.Run("When automatic approval is disabled", func(t *testing.T) {
term := NewFakeTerminalWithResponse("Y")
toolchainConfig := config.NewToolchainConfigObj(t, config.AutomaticApproval().Enabled(false))
newClient, newRESTClient, fakeClient := NewFakeClients(t, toolchainConfig, deployment)
newClient, fakeClient := NewFakeClients(t, toolchainConfig, deployment)
fakeClient.MockUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
if _, ok := obj.(*toolchainv1alpha1.ToolchainConfig); ok {
return fmt.Errorf("should not be called")
}
return fakeClient.Client.Update(ctx, obj, opts...)
}
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)
counter = 0

// when
Expand All @@ -143,11 +143,11 @@ func TestRegisterMember(t *testing.T) {
toolchainConfig := config.NewToolchainConfigObj(t, config.AutomaticApproval().Enabled(false))
toolchainConfig2 := config.NewToolchainConfigObj(t, config.AutomaticApproval().Enabled(true))
toolchainConfig2.Name = "config2"
newClient, newRESTClient, fakeClient := NewFakeClients(t, toolchainConfig, toolchainConfig2, deployment)
newClient, fakeClient := NewFakeClients(t, toolchainConfig, toolchainConfig2, deployment)
fakeClient.MockUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error {
return fmt.Errorf("should not be called")
}
ctx := clicontext.NewCommandContext(term, newClient, newRESTClient)
ctx := clicontext.NewCommandContext(term, newClient)
counter = 0

// when
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/adm/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
term := ioutils.NewTerminal(cmd.InOrStdin, cmd.OutOrStdout)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient, client.DefaultNewRESTClient)
ctx := clicontext.NewCommandContext(term, client.DefaultNewClient)

Check warning on line 32 in pkg/cmd/adm/restart.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/restart.go#L32

Added line #L32 was not covered by tests
return restart(ctx, targetCluster, args...)
},
}
Expand Down
Loading
Loading