Convert to assert.NilError

Using:

  git grep -l '^\s\+assert\.Check(t, err)$' | \
    xargs sed -i -e 's/^\(\s\+assert\)\.Check(t, err)$/\1.NilError(t, err)/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin
2018-03-06 14:44:13 -05:00
parent 0f11a310fd
commit baf65a5502
46 changed files with 173 additions and 173 deletions

View File

@ -14,11 +14,11 @@ import (
func TestGetOrGenerateNotaryKeyAndInitRepo(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
err = getOrGenerateRootKeyAndInitRepo(notaryRepo)
assert.Check(t, is.Error(err, "client is offline"))

View File

@ -36,7 +36,7 @@ func TestTrustKeyGenerateErrors(t *testing.T) {
}
tmpDir, err := ioutil.TempDir("", "docker-key-generate-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
@ -51,11 +51,11 @@ func TestTrustKeyGenerateErrors(t *testing.T) {
func TestGenerateKeySuccess(t *testing.T) {
pubKeyCWD, err := ioutil.TempDir("", "pub-keys-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(pubKeyCWD)
privKeyStorageDir, err := ioutil.TempDir("", "priv-keys-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(privKeyStorageDir)
passwd := "password"
@ -63,10 +63,10 @@ func TestGenerateKeySuccess(t *testing.T) {
// generate a single key
keyName := "alice"
privKeyFileStore, err := trustmanager.NewKeyFileStore(privKeyStorageDir, cannedPasswordRetriever)
assert.Check(t, err)
assert.NilError(t, err)
pubKeyPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore)
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, is.Equal(keyName, pubKeyPEM.Headers["role"]))
// the default GUN is empty
@ -77,10 +77,10 @@ func TestGenerateKeySuccess(t *testing.T) {
// check that an appropriate ~/<trust_dir>/private/<key_id>.key file exists
expectedPrivKeyDir := filepath.Join(privKeyStorageDir, notary.PrivDir)
_, err = os.Stat(expectedPrivKeyDir)
assert.Check(t, err)
assert.NilError(t, err)
keyFiles, err := ioutil.ReadDir(expectedPrivKeyDir)
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, is.Len(keyFiles, 1))
privKeyFilePath := filepath.Join(expectedPrivKeyDir, keyFiles[0].Name())
@ -96,28 +96,28 @@ func TestGenerateKeySuccess(t *testing.T) {
assert.Check(t, is.Equal("ENCRYPTED PRIVATE KEY", privKeyPEM.Type))
// check that the passphrase matches
_, err = tufutils.ParsePKCS8ToTufKey(privKeyPEM.Bytes, []byte(passwd))
assert.Check(t, err)
assert.NilError(t, err)
// check that the public key exists at the correct path if we use the helper:
returnedPath, err := writePubKeyPEMToDir(pubKeyPEM, keyName, pubKeyCWD)
assert.Check(t, err)
assert.NilError(t, err)
expectedPubKeyPath := filepath.Join(pubKeyCWD, keyName+".pub")
assert.Check(t, is.Equal(returnedPath, expectedPubKeyPath))
_, err = os.Stat(expectedPubKeyPath)
assert.Check(t, err)
assert.NilError(t, err)
// check that the public key is the only file output in CWD
cwdKeyFiles, err := ioutil.ReadDir(pubKeyCWD)
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, is.Len(cwdKeyFiles, 1))
}
func TestValidateKeyArgs(t *testing.T) {
pubKeyCWD, err := ioutil.TempDir("", "pub-keys-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(pubKeyCWD)
err = validateKeyArgs("a", pubKeyCWD)
assert.Check(t, err)
assert.NilError(t, err)
err = validateKeyArgs("a/b", pubKeyCWD)
assert.Error(t, err, "key name \"a/b\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character")

View File

@ -51,7 +51,7 @@ func TestTrustKeyLoadErrors(t *testing.T) {
},
}
tmpDir, err := ioutil.TempDir("", "docker-key-load-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
@ -118,24 +118,24 @@ func TestLoadKeyFromPath(t *testing.T) {
func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) {
privKeyDir, err := ioutil.TempDir("", "key-load-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(privKeyDir)
privKeyFilepath := filepath.Join(privKeyDir, "privkey.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, notary.PrivNoExecPerms))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir)
passwd := "password"
cannedPasswordRetriever := passphrase.ConstantRetriever(passwd)
keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension)
assert.Check(t, err)
assert.NilError(t, err)
privKeyImporters := []trustmanager.Importer{keyFileStore}
// get the privKeyBytes
privKeyBytes, err := getPrivKeyBytesFromPath(privKeyFilepath)
assert.Check(t, err)
assert.NilError(t, err)
// import the key to our keyStorageDir
assert.Check(t, loadPrivKeyBytesToStore(privKeyBytes, privKeyImporters, privKeyFilepath, "signer-name", cannedPasswordRetriever))
@ -143,7 +143,7 @@ func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte)
// check that the appropriate ~/<trust_dir>/private/<key_id>.key file exists
expectedImportKeyPath := filepath.Join(keyStorageDir, notary.PrivDir, privKeyID+"."+notary.KeyExtension)
_, err = os.Stat(expectedImportKeyPath)
assert.Check(t, err)
assert.NilError(t, err)
// verify the key content
from, _ := os.OpenFile(expectedImportKeyPath, os.O_RDONLY, notary.PrivExecPerms)
@ -157,7 +157,7 @@ func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte)
assert.Check(t, is.Equal("ENCRYPTED PRIVATE KEY", keyPEM.Type))
decryptedKey, err := tufutils.ParsePKCS8ToTufKey(keyPEM.Bytes, []byte(passwd))
assert.Check(t, err)
assert.NilError(t, err)
fixturePEM, _ := pem.Decode(privKeyFixture)
assert.Check(t, is.DeepEqual(fixturePEM.Bytes, decryptedKey.Private()))
}
@ -172,13 +172,13 @@ func TestLoadKeyTooPermissive(t *testing.T) {
func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) {
privKeyDir, err := ioutil.TempDir("", "key-load-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(privKeyDir)
privKeyFilepath := filepath.Join(privKeyDir, "privkey477.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0477))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir)
// import the key to our keyStorageDir
@ -204,13 +204,13 @@ func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) {
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0400))
_, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.Check(t, err)
assert.NilError(t, err)
privKeyFilepath = filepath.Join(privKeyDir, "privkey600.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0600))
_, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.Check(t, err)
assert.NilError(t, err)
}
var pubKeyFixture = []byte(`-----BEGIN PUBLIC KEY-----
@ -220,22 +220,22 @@ H3nzy2O6Q/ct4BjOBKa+WCdRtPo78bA+C/7t81ADQO8Jqaj59W50rwoqDQ==
func TestLoadPubKeyFailure(t *testing.T) {
pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(pubKeyDir)
pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem")
assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir)
passwd := "password"
cannedPasswordRetriever := passphrase.ConstantRetriever(passwd)
keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension)
assert.Check(t, err)
assert.NilError(t, err)
privKeyImporters := []trustmanager.Importer{keyFileStore}
pubKeyBytes, err := getPrivKeyBytesFromPath(pubKeyFilepath)
assert.Check(t, err)
assert.NilError(t, err)
// import the key to our keyStorageDir - it should fail
err = loadPrivKeyBytesToStore(pubKeyBytes, privKeyImporters, pubKeyFilepath, "signer-name", cannedPasswordRetriever)

View File

@ -136,7 +136,7 @@ func TestNewRevokeTrustAllSigConfirmation(t *testing.T) {
func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})

View File

@ -60,7 +60,7 @@ func TestTrustSignCommandErrors(t *testing.T) {
}
// change to a tmpdir
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
for _, tc := range testCases {
@ -83,15 +83,15 @@ func TestTrustSignCommandOfflineErrors(t *testing.T) {
func TestGetOrGenerateNotaryKey(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
// repo is empty, try making a root key
rootKeyA, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole)
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, rootKeyA != nil)
// we should only have one newly generated key
@ -101,7 +101,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) {
// this time we should get back the same key if we ask for another root key
rootKeyB, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole)
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, rootKeyB != nil)
// we should only have one newly generated key
@ -114,7 +114,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) {
// Now also try with a delegation key
releasesKey, err := getOrGenerateNotaryKey(notaryRepo, data.RoleName(trust.ReleasesRole))
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, releasesKey != nil)
// we should now have two keys
@ -128,20 +128,20 @@ func TestGetOrGenerateNotaryKey(t *testing.T) {
func TestAddStageSigners(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
// stage targets/user
userRole := data.RoleName("targets/user")
userKey := data.NewPublicKey("algoA", []byte("a"))
err = addStagedSigner(notaryRepo, userRole, []data.PublicKey{userKey})
assert.Check(t, err)
assert.NilError(t, err)
// check the changelist for four total changes: two on targets/releases and two on targets/user
cl, err := notaryRepo.GetChangelist()
assert.Check(t, err)
assert.NilError(t, err)
changeList := cl.List()
assert.Check(t, is.Len(changeList, 4))
// ordering is determinstic:
@ -213,11 +213,11 @@ func TestAddStageSigners(t *testing.T) {
func TestGetSignedManifestHashAndSize(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
target := &client.Target{}
target.Hashes, target.Length, err = getSignedManifestHashAndSize(notaryRepo, "test")
assert.Check(t, is.Error(err, "client is offline"))
@ -241,11 +241,11 @@ func TestGetReleasedTargetHashAndSize(t *testing.T) {
func TestCreateTarget(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
_, err = createTarget(notaryRepo, "")
assert.Check(t, is.Error(err, "No tag specified"))
_, err = createTarget(notaryRepo, "1")
@ -254,11 +254,11 @@ func TestCreateTarget(t *testing.T) {
func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
_, err = getExistingSignatureInfoForReleasedTag(notaryRepo, "test")
assert.Check(t, is.Error(err, "client is offline"))
}
@ -274,7 +274,7 @@ func TestPrettyPrintExistingSignatureInfo(t *testing.T) {
func TestSignCommandChangeListIsCleanedOnError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
@ -288,7 +288,7 @@ func TestSignCommandChangeListIsCleanedOnError(t *testing.T) {
assert.Assert(t, is.ErrorContains(err, ""))
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "docker.io/library/ubuntu", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.Check(t, err)
assert.NilError(t, err)
cl, err := notaryRepo.GetChangelist()
assert.NilError(t, err)
assert.Check(t, is.Equal(len(cl.List()), 0))

View File

@ -51,7 +51,7 @@ func TestTrustSignerAddErrors(t *testing.T) {
},
}
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
@ -67,12 +67,12 @@ func TestTrustSignerAddErrors(t *testing.T) {
func TestSignerAddCommandNoTargetsKey(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
tmpfile, err := ioutil.TempFile("", "pemfile")
assert.Check(t, err)
assert.NilError(t, err)
defer os.Remove(tmpfile.Name())
cli := test.NewFakeCli(&fakeClient{})
@ -86,7 +86,7 @@ func TestSignerAddCommandNoTargetsKey(t *testing.T) {
func TestSignerAddCommandBadKeyPath(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
@ -101,12 +101,12 @@ func TestSignerAddCommandBadKeyPath(t *testing.T) {
func TestSignerAddCommandInvalidRepoName(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-")
assert.Check(t, err)
assert.NilError(t, err)
defer os.RemoveAll(pubKeyDir)
pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem")
assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
@ -130,7 +130,7 @@ func TestIngestPublicKeys(t *testing.T) {
assert.Check(t, is.Error(err, "unable to read public key from file: open foo: no such file or directory"))
// Call with real file path
tmpfile, err := ioutil.TempFile("", "pemfile")
assert.Check(t, err)
assert.NilError(t, err)
defer os.Remove(tmpfile.Name())
_, err = ingestPublicKeys([]string{tmpfile.Name()})
assert.Check(t, is.Error(err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name())))

View File

@ -90,7 +90,7 @@ func TestRemoveLastSignerWarning(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository)
err := removeSigner(cli, signerRemoveOptions{signer: "alice", repos: []string{"signed-repo"}, forceYes: false})
assert.Check(t, err)
assert.NilError(t, err)
assert.Check(t, is.Contains(cli.OutBuffer().String(),
"The signer \"alice\" signed the last released version of signed-repo. "+
"Removing this signer will make signed-repo unpullable. "+