Skip to content

Commit b98aea5

Browse files
Rename assertNotNil to assertNoError, since the former name is incorrect (#230)
1 parent 1b4561f commit b98aea5

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

client/testdata/go-tuf-transition-M3/generate.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ type persistedKeys struct {
2222
Data []*data.PrivateKey `json:"data"`
2323
}
2424

25-
func assertNotNil(err error) {
25+
func assertNoError(err error) {
2626
if err != nil {
2727
panic(fmt.Sprintf("assertion failed: %s", err))
2828
}
2929
}
3030

3131
func copyRepo(src string, dst string) {
3232
cmd := exec.Command("cp", "-r", src, dst)
33-
assertNotNil(cmd.Run())
33+
assertNoError(cmd.Run())
3434
}
3535

3636
func newRepo(dir string) *tuf.Repo {
3737
repo, err := tuf.NewRepoIndent(tuf.FileSystemStore(dir, nil), "", "\t")
38-
assertNotNil(err)
38+
assertNoError(err)
3939

4040
return repo
4141
}
4242

4343
func commit(dir string, repo *tuf.Repo) {
44-
assertNotNil(repo.SnapshotWithExpires(expirationDate))
45-
assertNotNil(repo.TimestampWithExpires(expirationDate))
46-
assertNotNil(repo.Commit())
44+
assertNoError(repo.SnapshotWithExpires(expirationDate))
45+
assertNoError(repo.TimestampWithExpires(expirationDate))
46+
assertNoError(repo.Commit())
4747

4848
// Remove the keys directory to make sure we don't accidentally use a key.
49-
assertNotNil(os.RemoveAll(filepath.Join(dir, "keys")))
49+
assertNoError(os.RemoveAll(filepath.Join(dir, "keys")))
5050
}
5151

5252
func addKeys(repo *tuf.Repo, roleKeys map[string][]*data.PrivateKey) {
5353
for role, keyList := range roleKeys {
5454
for _, key := range keyList {
5555
signer, err := keys.GetSigner(key)
56-
assertNotNil(err)
57-
assertNotNil(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
56+
assertNoError(err)
57+
assertNoError(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
5858
}
5959
}
6060
}
@@ -63,27 +63,27 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
6363
paths := []string{}
6464
for file, data := range files {
6565
path := filepath.Join(dir, "staged", "targets", file)
66-
assertNotNil(os.MkdirAll(filepath.Dir(path), 0755))
67-
assertNotNil(ioutil.WriteFile(path, data, 0644))
66+
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
67+
assertNoError(ioutil.WriteFile(path, data, 0644))
6868
paths = append(paths, file)
6969
}
70-
assertNotNil(repo.AddTargetsWithExpires(paths, nil, expirationDate))
70+
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))
7171
}
7272

7373
func revokeKeys(repo *tuf.Repo, role string, keyList []*data.PrivateKey) {
7474
for _, key := range keyList {
7575
signer, err := keys.GetSigner(key)
76-
assertNotNil(err)
77-
assertNotNil(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
76+
assertNoError(err)
77+
assertNoError(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
7878
}
7979
}
8080

8181
func generateRepos(dir string, consistentSnapshot bool) {
8282
f, err := os.Open("../keys.json")
83-
assertNotNil(err)
83+
assertNoError(err)
8484

8585
var roleKeys map[string][][]*data.PrivateKey
86-
assertNotNil(json.NewDecoder(f).Decode(&roleKeys))
86+
assertNoError(json.NewDecoder(f).Decode(&roleKeys))
8787

8888
// Collect all the initial keys we'll use when creating repositories.
8989
// We'll modify this to reflect rotated keys.
@@ -140,7 +140,7 @@ func generateRepos(dir string, consistentSnapshot bool) {
140140

141141
func main() {
142142
cwd, err := os.Getwd()
143-
assertNotNil(err)
143+
assertNoError(err)
144144

145145
for _, consistentSnapshot := range []bool{false, true} {
146146
name := fmt.Sprintf("consistent-snapshot-%t", consistentSnapshot)

client/testdata/go-tuf-transition-M4/generate.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@ type persistedKeys struct {
2222
Data []*data.PrivateKey `json:"data"`
2323
}
2424

25-
func assertNotNil(err error) {
25+
func assertNoError(err error) {
2626
if err != nil {
2727
panic(fmt.Sprintf("assertion failed: %s", err))
2828
}
2929
}
3030

3131
func copyRepo(src string, dst string) {
3232
cmd := exec.Command("cp", "-r", src, dst)
33-
assertNotNil(cmd.Run())
33+
assertNoError(cmd.Run())
3434
}
3535

3636
func newRepo(dir string) *tuf.Repo {
3737
repo, err := tuf.NewRepoIndent(tuf.FileSystemStore(dir, nil), "", "\t")
38-
assertNotNil(err)
38+
assertNoError(err)
3939

4040
return repo
4141
}
4242

4343
func commit(dir string, repo *tuf.Repo) {
44-
assertNotNil(repo.SnapshotWithExpires(expirationDate))
45-
assertNotNil(repo.TimestampWithExpires(expirationDate))
46-
assertNotNil(repo.Commit())
44+
assertNoError(repo.SnapshotWithExpires(expirationDate))
45+
assertNoError(repo.TimestampWithExpires(expirationDate))
46+
assertNoError(repo.Commit())
4747

4848
// Remove the keys directory to make sure we don't accidentally use a key.
49-
assertNotNil(os.RemoveAll(filepath.Join(dir, "keys")))
49+
assertNoError(os.RemoveAll(filepath.Join(dir, "keys")))
5050
}
5151

5252
func addKeys(repo *tuf.Repo, roleKeys map[string][]*data.PrivateKey) {
5353
for role, keys := range roleKeys {
5454
for _, key := range keys {
55-
assertNotNil(repo.AddPrivateKeyWithExpires(role, key, expirationDate))
55+
assertNoError(repo.AddPrivateKeyWithExpires(role, key, expirationDate))
5656
}
5757
}
5858
}
@@ -61,27 +61,27 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
6161
paths := []string{}
6262
for file, data := range files {
6363
path := filepath.Join(dir, "staged", "targets", file)
64-
assertNotNil(os.MkdirAll(filepath.Dir(path), 0755))
65-
assertNotNil(ioutil.WriteFile(path, data, 0644))
64+
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
65+
assertNoError(ioutil.WriteFile(path, data, 0644))
6666
paths = append(paths, file)
6767
}
68-
assertNotNil(repo.AddTargetsWithExpires(paths, nil, expirationDate))
68+
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))
6969
}
7070

7171
func revokeKeys(repo *tuf.Repo, role string, keyList []*data.PrivateKey) {
7272
for _, key := range keyList {
7373
signer, err := keys.GetSigner(key)
74-
assertNotNil(err)
75-
assertNotNil(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
74+
assertNoError(err)
75+
assertNoError(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
7676
}
7777
}
7878

7979
func generateRepos(dir string, consistentSnapshot bool) {
8080
f, err := os.Open("../keys.json")
81-
assertNotNil(err)
81+
assertNoError(err)
8282

8383
var roleKeys map[string][][]*data.PrivateKey
84-
assertNotNil(json.NewDecoder(f).Decode(&roleKeys))
84+
assertNoError(json.NewDecoder(f).Decode(&roleKeys))
8585

8686
// Collect all the initial keys we'll use when creating repositories.
8787
// We'll modify this to reflect rotated keys.
@@ -138,7 +138,7 @@ func generateRepos(dir string, consistentSnapshot bool) {
138138

139139
func main() {
140140
cwd, err := os.Getwd()
141-
assertNotNil(err)
141+
assertNoError(err)
142142

143143
for _, consistentSnapshot := range []bool{false, true} {
144144
name := fmt.Sprintf("consistent-snapshot-%t", consistentSnapshot)

client/testdata/go-tuf/generator/generator.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ type persistedKeys struct {
2222
Data []*data.PrivateKey `json:"data"`
2323
}
2424

25-
func assertNotNil(err error) {
25+
func assertNoError(err error) {
2626
if err != nil {
2727
panic(fmt.Sprintf("assertion failed: %s", err))
2828
}
2929
}
3030

3131
func copyRepo(src string, dst string) {
3232
cmd := exec.Command("cp", "-r", src, dst)
33-
assertNotNil(cmd.Run())
33+
assertNoError(cmd.Run())
3434
}
3535

3636
func newRepo(dir string) *tuf.Repo {
3737
repo, err := tuf.NewRepoIndent(tuf.FileSystemStore(dir, nil), "", "\t")
38-
assertNotNil(err)
38+
assertNoError(err)
3939

4040
return repo
4141
}
4242

4343
func commit(dir string, repo *tuf.Repo) {
44-
assertNotNil(repo.SnapshotWithExpires(expirationDate))
45-
assertNotNil(repo.TimestampWithExpires(expirationDate))
46-
assertNotNil(repo.Commit())
44+
assertNoError(repo.SnapshotWithExpires(expirationDate))
45+
assertNoError(repo.TimestampWithExpires(expirationDate))
46+
assertNoError(repo.Commit())
4747

4848
// Remove the keys directory to make sure we don't accidentally use a key.
49-
assertNotNil(os.RemoveAll(filepath.Join(dir, "keys")))
49+
assertNoError(os.RemoveAll(filepath.Join(dir, "keys")))
5050
}
5151

5252
func addKeys(repo *tuf.Repo, roleKeys map[string][]*data.PrivateKey) {
5353
for role, keyList := range roleKeys {
5454
for _, key := range keyList {
5555
signer, err := keys.GetSigner(key)
56-
assertNotNil(err)
57-
assertNotNil(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
56+
assertNoError(err)
57+
assertNoError(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
5858
}
5959
}
6060
}
@@ -63,18 +63,18 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
6363
paths := []string{}
6464
for file, data := range files {
6565
path := filepath.Join(dir, "staged", "targets", file)
66-
assertNotNil(os.MkdirAll(filepath.Dir(path), 0755))
67-
assertNotNil(ioutil.WriteFile(path, data, 0644))
66+
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
67+
assertNoError(ioutil.WriteFile(path, data, 0644))
6868
paths = append(paths, file)
6969
}
70-
assertNotNil(repo.AddTargetsWithExpires(paths, nil, expirationDate))
70+
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))
7171
}
7272

7373
func revokeKeys(repo *tuf.Repo, role string, keyList []*data.PrivateKey) {
7474
for _, key := range keyList {
7575
signer, err := keys.GetSigner(key)
76-
assertNotNil(err)
77-
assertNotNil(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
76+
assertNoError(err)
77+
assertNoError(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
7878
}
7979
}
8080

@@ -134,10 +134,10 @@ func generateRepos(dir string, roleKeys map[string][][]*data.PrivateKey, consist
134134

135135
func Generate(dir string, keysPath string, consistentSnapshot bool) {
136136
f, err := os.Open(keysPath)
137-
assertNotNil(err)
137+
assertNoError(err)
138138

139139
var roleKeys map[string][][]*data.PrivateKey
140-
assertNotNil(json.NewDecoder(f).Decode(&roleKeys))
140+
assertNoError(json.NewDecoder(f).Decode(&roleKeys))
141141

142142
log.Printf("generating %s", dir)
143143

client/testdata/tools/gen-keys.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ func main() {
3030

3131
for i := 0; i < 2; i++ {
3232
signer, err := keys.GenerateEd25519Key()
33-
assertNotNil(err)
33+
assertNoError(err)
3434
keys = append(keys, []*data.PrivateKey{signer})
3535
}
3636

3737
roles[name] = keys
3838
}
3939

4040
s, err := json.MarshalIndent(&roles, "", " ")
41-
assertNotNil(err)
41+
assertNoError(err)
4242

4343
ioutil.WriteFile("keys.json", []byte(s), 0644)
4444
}
4545

46-
func assertNotNil(err error) {
46+
func assertNoError(err error) {
4747
if err != nil {
4848
panic(fmt.Sprintf("assertion failed: %s", err))
4949
}

0 commit comments

Comments
 (0)