ensure that kubernetes GetKubeConfigWithExpiry fetches a token-based …#1001
Conversation
…kubeconfig since it's the only kind that has expiration
| } | ||
| q := req.URL.Query() | ||
| if get.Type != "" { | ||
| if get != nil && get.Type != "" { |
DO-rrao
left a comment
There was a problem hiding this comment.
Overall the logic is correct and the changes are well-scoped. A couple of convention nits and a suggestion for test coverage below.
| assert.True(t, ok) | ||
| assert.Len(t, expirySeconds, 1) | ||
| assert.Contains(t, expirySeconds, "3600") | ||
| assert.Equal(t, r.URL.Query()["type"], []string{"token"}) |
There was a problem hiding this comment.
Nit: This assertion style is inconsistent with the rest of the test suite. Elsewhere (e.g., GetKubeConfig_WithType at line 520), single-value query params are asserted using .Get():
assert.Equal(t, "token", r.URL.Query().Get("type"))Also, assert.Equal conventionally takes (t, expected, actual) — the arguments here are reversed.
Suggested fix:
| assert.Equal(t, r.URL.Query()["type"], []string{"token"}) | |
| assert.Equal(t, "token", r.URL.Query().Get("type")) |
There was a problem hiding this comment.
Updated, thank you!
| } | ||
| q := req.URL.Query() | ||
| if get.Type != "" { | ||
| if get != nil && get.Type != "" { |
There was a problem hiding this comment.
The fix is correct — but there's no test that actually exercises the get == nil path. The existing TestKubernetesClusters_GetKubeConfig passes &KubernetesClusterKubeconfigGetRequest{} (empty struct), not nil.
Consider adding a test like:
func TestKubernetesClusters_GetKubeConfig_NilRequest(t *testing.T) {
setup()
defer teardown()
kubeSvc := client.Kubernetes
want := "some YAML"
blob := []byte(want)
mux.HandleFunc("/v2/kubernetes/clusters/deadbeef-dead-4aa5-beef-deadbeef347d/kubeconfig", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
_, isTypeQueryParamSet := r.URL.Query()["type"]
assert.False(t, isTypeQueryParamSet)
fmt.Fprint(w, want)
})
got, _, err := kubeSvc.GetKubeConfig(ctx, "deadbeef-dead-4aa5-beef-deadbeef347d", nil)
require.NoError(t, err)
require.Equal(t, blob, got.KubeconfigYAML)
}Also worth noting: GetCredentials (line 856) has the same nil-pointer risk — get.ExpirySeconds is accessed without checking if get is nil. Could be a follow-up fix.
There was a problem hiding this comment.
Added the test as well as a nil-check and test for GetCredentials. Thank you!
…kubeconfig since it's the only kind that has expiration