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

ssh - completion with machine objects #347

Merged
merged 16 commits into from
Jan 10, 2024
Prev Previous commit
Next Next commit
add unit test
  • Loading branch information
tedteng committed Dec 11, 2023
commit 2fc9b0c377191353b37a8abe96878ddc6f3e3c27
26 changes: 26 additions & 0 deletions internal/client/garden/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
authenticationv1 "k8s.io/api/authentication/v1"
authorizationv1 "k8s.io/api/authorization/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -354,4 +355,29 @@ var _ = Describe("Client", func() {
Expect(username).To(Equal(userCN))
})
})

Describe("CheckUserRoles", func() {
It("Should return the user roles is true as operator", func() {
config := fake.NewTokenConfig("garden")
cic := createInterceptingClient{
Client: fake.NewClientWithObjects(),
createInterceptor: func(ctx context.Context, object client.Object, option ...client.CreateOption) error {
if tr, ok := object.(*authorizationv1.SelfSubjectAccessReview); ok {
tr.ObjectMeta.Name = "foo" // must be set or else the fake client will error because no name was provided
tr.Status.Allowed = true
}
return nil
},
}
gardenClient = clientgarden.NewClient(
clientcmd.NewDefaultClientConfig(*config, nil),
cic,
gardenName,
)

operator, err := gardenClient.CheckUserRoles(ctx)
Expect(err).To(BeNil())
Expect(operator).To(Equal(true))
})
})
})
2 changes: 2 additions & 0 deletions pkg/cmd/ssh/ssh_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
operationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
machinev1alpha1 "github.com/gardener/machine-controller-manager/pkg/apis/machine/v1alpha1"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -23,6 +24,7 @@ import (
func init() {
utilruntime.Must(gardencorev1beta1.AddToScheme(scheme.Scheme))
utilruntime.Must(operationsv1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(machinev1alpha1.AddToScheme(scheme.Scheme))
}

func TestCommand(t *testing.T) {
Expand Down