Skip to content

Commit

Permalink
backend: Add tests for rename clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Kautilya Tripathi <[email protected]>
  • Loading branch information
knrt10 committed Jul 22, 2024
1 parent 294f7f2 commit 07d3410
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
61 changes: 61 additions & 0 deletions backend/cmd/headlamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,64 @@ func TestHandleClusterAPI_XForwardedHost(t *testing.T) {
assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, "OK", rr.Body.String())
}

func TestRenameCluster(t *testing.T) {
kubeConfigByte, err := os.ReadFile("./headlamp_testdata/kubeconfig")
require.NoError(t, err)

kubeConfig := base64.StdEncoding.EncodeToString(kubeConfigByte)
req := ClusterReq{
KubeConfig: &kubeConfig,
}
cache := cache.New[interface{}]()
kubeConfigStore := kubeconfig.NewContextStore()

c := HeadlampConfig{
useInCluster: false,
kubeConfigPath: "./headlamp_testdata/kubeconfig",
enableDynamicClusters: true,
cache: cache,
kubeConfigStore: kubeConfigStore,
}
handler := createHeadlampHandler(&c)

r, err := getResponseFromRestrictedEndpoint(handler, "POST", "/cluster", req)
if err != nil {
t.Fatal(err)
}

clusters := c.getClusters()

assert.Equal(t, http.StatusCreated, r.Code)
assert.Equal(t, 2, len(clusters))

tests := []struct {
name string
clusterReq RenameClusterRequest
expectedState int
}{
{
name: "passStatefull",
clusterReq: RenameClusterRequest{
NewClusterName: "minikubetestworks",
Stateless: false,
Source: "kubeconfig",
},
expectedState: http.StatusCreated,
},
{
name: "stateless",
clusterReq: RenameClusterRequest{
NewClusterName: "minikubetestworks",
Stateless: true,
},
expectedState: http.StatusCreated,
},
}

for _, tc := range tests {
r, err = getResponseFromRestrictedEndpoint(handler, "PUT", "/cluster/minikubetest", tc.clusterReq)
require.NoError(t, err)
assert.Equal(t, tc.expectedState, r.Code)
}
}
36 changes: 36 additions & 0 deletions backend/cmd/headlamp_testdata/kubeconfig_rename
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SaDJKWQpKWDFycmFMdGNTbzVuNG1DVy9oeE5YdHpCMlIzWkhPU0hnNmF2R3JNeFY4ZlpCdmtBdEJFaUYzM2JvRThzZzVhCjhhWHRFTjR5bzlZQ2FZc2ZXK2tNNlZDRUdtVWd5bm13aXltYTBzSW5USlZ1R3ZVbDVucVhjUHJJdW9OTVVrTUwKdCsrckxCb0NwY2xrN09VSTA0dXZvanpxc2hsQ0JiMURSOXRwT0s0Kys0UGdPait6OXZ0N3g0dzhMYlhvQmtvegozOEJyVEoyQ3NqbU0xS2ZqZXlpNWdHVmFjeE9YSXRjbXprNzRpQzZ0SjdqVm1MVmNacEc5ZElvcFk5WTBaTkQ0CmQzZjlmOGdCWkJzaXA0a3gxMmFxMlJ5dzFYNGVOaFY2dW5OaCtHVHNhNlFDSlJ0Zk9FK1Q4Njd2ZHlPbjZMb2wKYWQ4PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
extensions:
- extension:
last-update: Mon, 26 Dec 2022 20:33:03 IST
provider: minikubetest.sigs.k8s.io
version: v1.28.0
name: cluster_info
server: https://127.0.0.1:60279
name: minikubetest
contexts:
- context:
cluster: minikubetest
extensions:
- extension:
last-update: Mon, 26 Dec 2022 20:33:03 IST
provider: minikubetest.sigs.k8s.io
version: v1.28.0
name: context_info
- extension:
creationTimestamp: null
customName: minikubetestworks
name: headlamp_info
namespace: default
user: minikubetest
name: minikubetest
current-context: minikubetest
kind: Config
preferences: {}
users:
- name: minikubetest
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJekNDQWd1Z0F3SUJBZ0lJZlJpZk1qZWl1eFV3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBNE1qWXhNVEEwTlROYUZ3MHlOREF4TURJeE1ESXhNelZhTURZeApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sc3dHUV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