mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-07 00:27:16 +00:00
Add a library.PinnipedCLIPath() test helper, with caching.
Caching saves us a little bit of time now that we're using the CLI in more and more tests. Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
@@ -42,7 +42,7 @@ func TestCLIGetKubeconfigStaticToken(t *testing.T) {
|
||||
authenticator := library.CreateTestWebhookAuthenticator(ctx, t)
|
||||
|
||||
// Build pinniped CLI.
|
||||
pinnipedExe := buildPinnipedCLI(t)
|
||||
pinnipedExe := library.PinnipedCLIPath(t)
|
||||
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
@@ -109,25 +109,6 @@ func TestCLIGetKubeconfigStaticToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func buildPinnipedCLI(t *testing.T) string {
|
||||
t.Helper()
|
||||
|
||||
pinnipedExeDir, err := ioutil.TempDir("", "pinniped-cli-test-*")
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, os.RemoveAll(pinnipedExeDir)) })
|
||||
|
||||
pinnipedExe := filepath.Join(pinnipedExeDir, "pinniped")
|
||||
output, err := exec.Command(
|
||||
"go",
|
||||
"build",
|
||||
"-o",
|
||||
pinnipedExe,
|
||||
"go.pinniped.dev/cmd/pinniped",
|
||||
).CombinedOutput()
|
||||
require.NoError(t, err, string(output))
|
||||
return pinnipedExe
|
||||
}
|
||||
|
||||
func runPinnipedCLI(t *testing.T, pinnipedExe string, args ...string) (string, string) {
|
||||
t.Helper()
|
||||
var stdout, stderr bytes.Buffer
|
||||
@@ -145,8 +126,7 @@ func TestCLILoginOIDC(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
// Build pinniped CLI.
|
||||
t.Logf("building CLI binary")
|
||||
pinnipedExe := buildPinnipedCLI(t)
|
||||
pinnipedExe := library.PinnipedCLIPath(t)
|
||||
|
||||
// Run "pinniped login oidc" to get an ExecCredential struct with an OIDC ID token.
|
||||
credOutput, sessionCachePath := runPinniedLoginOIDC(ctx, t, pinnipedExe)
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestSuccessfulCredentialRequest(t *testing.T) {
|
||||
return library.CreateTestJWTAuthenticator(ctx, t)
|
||||
},
|
||||
token: func(t *testing.T) (string, string, []string) {
|
||||
pinnipedExe := buildPinnipedCLI(t)
|
||||
pinnipedExe := library.PinnipedCLIPath(t)
|
||||
credOutput, _ := runPinniedLoginOIDC(ctx, t, pinnipedExe)
|
||||
token := credOutput.Status.Token
|
||||
|
||||
|
||||
Reference in New Issue
Block a user