Files
nvke/cli/internal/auth/cache_test.go
Davanum SrinivasandClaude Fable 5.1 668bc38a9b feat(cli)!: rename nkectl to nvkectl, keeping the old names for one release (#1456)
The binary, its directory, its config directory and its environment
variables take the new name. For one release the previous names still
work: every NVKECTL_* setting is also read under its NKECTL_* name with a
deprecation warning (the NKECTL_CWE_* names of the generation before are
no longer read), a config file left under nkectl/ is read and copied to
nvkectl/ once, and releases publish both nvkectl-<os>-<arch> and
nkectl-<os>-<arch>, to GitHub and to S3 under the existing prefix.

The e2e helper package, the e2e test, the smoke and fetch scripts and
the bootstrap e2e workflow follow the binary; the fetch script accepts a
release that carries only the old asset name. The CLI's own documents
and the two installation documents that print the download URLs change
with it.

Kept on purpose: the NVCR repository name until an nvkectl repository
exists in the NGC org, the S3 prefix the publishing role's policy names,
and the prose in the other documents.

BREAKING CHANGE: the CLI is installed and invoked as nvkectl. The
previous binary name, environment variable names and config directory
are honoured for one release, as described above.

Closes #1455

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 17:04:03 -04:00

51 lines
1.1 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package auth
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"time"
)
func TestTokenCacheRoundTrip(t *testing.T) {
const endpoint = "https://nke.example.internal"
token := cachedToken{
Value: "cached-token",
ExpiresAt: time.Now().Add(tokenLifetime),
}
path := filepath.Join(t.TempDir(), "nvkectl", "tokens.json")
cache := &tokenCache{
path: path,
tokens: make(map[string]cachedToken),
}
cache.store(endpoint, token)
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
var loaded map[string]cachedToken
if err := json.Unmarshal(data, &loaded); err != nil {
t.Fatal(err)
}
got, ok := loaded[endpoint]
if !ok {
t.Fatal("cache did not contain the stored endpoint")
}
if got.Value != token.Value || !got.ExpiresAt.Equal(token.ExpiresAt) {
t.Fatalf("cached token = %#v, want %#v", got, token)
}
info, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if gotMode := info.Mode().Perm(); gotMode != 0o600 {
t.Fatalf("cache mode = %#o, want 0600", gotMode)
}
}