cli/command/trust: fix "usetesting" linting errors

cli/command/trust/signer_add_test.go:71:18: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestSignerAddCommandNoTargetsKey (usetesting)
        tmpfile, err := os.CreateTemp("", "pemfile")
                        ^
    cli/command/trust/signer_add_test.go:133:18: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestIngestPublicKeys (usetesting)
        tmpfile, err := os.CreateTemp("", "pemfile")
                        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2025-02-17 22:59:41 +01:00
parent b2f3c12497
commit aca0bd7757
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C

View File

@ -68,19 +68,19 @@ func TestTrustSignerAddErrors(t *testing.T) {
func TestSignerAddCommandNoTargetsKey(t *testing.T) {
config.SetDir(t.TempDir())
tmpfile, err := os.CreateTemp("", "pemfile")
tmpDir := t.TempDir()
tmpFile, err := os.CreateTemp(tmpDir, "pemfile")
assert.NilError(t, err)
tmpfile.Close()
defer os.Remove(tmpfile.Name())
assert.Check(t, tmpFile.Close())
cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository)
cmd := newSignerAddCommand(cli)
cmd.SetArgs([]string{"--key", tmpfile.Name(), "alice", "alpine", "linuxkit/alpine"})
cmd.SetArgs([]string{"--key", tmpFile.Name(), "alice", "alpine", "linuxkit/alpine"})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
assert.Error(t, cmd.Execute(), fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
assert.Error(t, cmd.Execute(), fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpFile.Name()))
}
func TestSignerAddCommandBadKeyPath(t *testing.T) {
@ -130,10 +130,10 @@ func TestIngestPublicKeys(t *testing.T) {
}
assert.Error(t, err, expectedError)
// Call with real file path
tmpfile, err := os.CreateTemp("", "pemfile")
tmpDir := t.TempDir()
tmpFile, err := os.CreateTemp(tmpDir, "pemfile")
assert.NilError(t, err)
tmpfile.Close()
defer os.Remove(tmpfile.Name())
_, err = ingestPublicKeys([]string{tmpfile.Name()})
assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
assert.Check(t, tmpFile.Close())
_, err = ingestPublicKeys([]string{tmpFile.Name()})
assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpFile.Name()))
}