Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename assertNotNil to assertNoError, since the former name is incorrect #230

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions client/testdata/go-tuf-transition-M3/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ type persistedKeys struct {
Data []*data.PrivateKey `json:"data"`
}

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

func copyRepo(src string, dst string) {
cmd := exec.Command("cp", "-r", src, dst)
assertNotNil(cmd.Run())
assertNoError(cmd.Run())
}

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

return repo
}

func commit(dir string, repo *tuf.Repo) {
assertNotNil(repo.SnapshotWithExpires(expirationDate))
assertNotNil(repo.TimestampWithExpires(expirationDate))
assertNotNil(repo.Commit())
assertNoError(repo.SnapshotWithExpires(expirationDate))
assertNoError(repo.TimestampWithExpires(expirationDate))
assertNoError(repo.Commit())

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

func addKeys(repo *tuf.Repo, roleKeys map[string][]*data.PrivateKey) {
for role, keyList := range roleKeys {
for _, key := range keyList {
signer, err := keys.GetSigner(key)
assertNotNil(err)
assertNotNil(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
assertNoError(err)
assertNoError(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
}
}
}
Expand All @@ -63,27 +63,27 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
paths := []string{}
for file, data := range files {
path := filepath.Join(dir, "staged", "targets", file)
assertNotNil(os.MkdirAll(filepath.Dir(path), 0755))
assertNotNil(ioutil.WriteFile(path, data, 0644))
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
assertNoError(ioutil.WriteFile(path, data, 0644))
paths = append(paths, file)
}
assertNotNil(repo.AddTargetsWithExpires(paths, nil, expirationDate))
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))
}

func revokeKeys(repo *tuf.Repo, role string, keyList []*data.PrivateKey) {
for _, key := range keyList {
signer, err := keys.GetSigner(key)
assertNotNil(err)
assertNotNil(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
assertNoError(err)
assertNoError(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
}
}

func generateRepos(dir string, consistentSnapshot bool) {
f, err := os.Open("../keys.json")
assertNotNil(err)
assertNoError(err)

var roleKeys map[string][][]*data.PrivateKey
assertNotNil(json.NewDecoder(f).Decode(&roleKeys))
assertNoError(json.NewDecoder(f).Decode(&roleKeys))

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

func main() {
cwd, err := os.Getwd()
assertNotNil(err)
assertNoError(err)

for _, consistentSnapshot := range []bool{false, true} {
name := fmt.Sprintf("consistent-snapshot-%t", consistentSnapshot)
Expand Down
32 changes: 16 additions & 16 deletions client/testdata/go-tuf-transition-M4/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@ type persistedKeys struct {
Data []*data.PrivateKey `json:"data"`
}

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

func copyRepo(src string, dst string) {
cmd := exec.Command("cp", "-r", src, dst)
assertNotNil(cmd.Run())
assertNoError(cmd.Run())
}

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

return repo
}

func commit(dir string, repo *tuf.Repo) {
assertNotNil(repo.SnapshotWithExpires(expirationDate))
assertNotNil(repo.TimestampWithExpires(expirationDate))
assertNotNil(repo.Commit())
assertNoError(repo.SnapshotWithExpires(expirationDate))
assertNoError(repo.TimestampWithExpires(expirationDate))
assertNoError(repo.Commit())

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

func addKeys(repo *tuf.Repo, roleKeys map[string][]*data.PrivateKey) {
for role, keys := range roleKeys {
for _, key := range keys {
assertNotNil(repo.AddPrivateKeyWithExpires(role, key, expirationDate))
assertNoError(repo.AddPrivateKeyWithExpires(role, key, expirationDate))
}
}
}
Expand All @@ -61,27 +61,27 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
paths := []string{}
for file, data := range files {
path := filepath.Join(dir, "staged", "targets", file)
assertNotNil(os.MkdirAll(filepath.Dir(path), 0755))
assertNotNil(ioutil.WriteFile(path, data, 0644))
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
assertNoError(ioutil.WriteFile(path, data, 0644))
paths = append(paths, file)
}
assertNotNil(repo.AddTargetsWithExpires(paths, nil, expirationDate))
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))
}

func revokeKeys(repo *tuf.Repo, role string, keyList []*data.PrivateKey) {
for _, key := range keyList {
signer, err := keys.GetSigner(key)
assertNotNil(err)
assertNotNil(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
assertNoError(err)
assertNoError(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
}
}

func generateRepos(dir string, consistentSnapshot bool) {
f, err := os.Open("../keys.json")
assertNotNil(err)
assertNoError(err)

var roleKeys map[string][][]*data.PrivateKey
assertNotNil(json.NewDecoder(f).Decode(&roleKeys))
assertNoError(json.NewDecoder(f).Decode(&roleKeys))

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

func main() {
cwd, err := os.Getwd()
assertNotNil(err)
assertNoError(err)

for _, consistentSnapshot := range []bool{false, true} {
name := fmt.Sprintf("consistent-snapshot-%t", consistentSnapshot)
Expand Down
32 changes: 16 additions & 16 deletions client/testdata/go-tuf/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ type persistedKeys struct {
Data []*data.PrivateKey `json:"data"`
}

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

func copyRepo(src string, dst string) {
cmd := exec.Command("cp", "-r", src, dst)
assertNotNil(cmd.Run())
assertNoError(cmd.Run())
}

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

return repo
}

func commit(dir string, repo *tuf.Repo) {
assertNotNil(repo.SnapshotWithExpires(expirationDate))
assertNotNil(repo.TimestampWithExpires(expirationDate))
assertNotNil(repo.Commit())
assertNoError(repo.SnapshotWithExpires(expirationDate))
assertNoError(repo.TimestampWithExpires(expirationDate))
assertNoError(repo.Commit())

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

func addKeys(repo *tuf.Repo, roleKeys map[string][]*data.PrivateKey) {
for role, keyList := range roleKeys {
for _, key := range keyList {
signer, err := keys.GetSigner(key)
assertNotNil(err)
assertNotNil(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
assertNoError(err)
assertNoError(repo.AddPrivateKeyWithExpires(role, signer, expirationDate))
}
}
}
Expand All @@ -63,18 +63,18 @@ func addTargets(repo *tuf.Repo, dir string, files map[string][]byte) {
paths := []string{}
for file, data := range files {
path := filepath.Join(dir, "staged", "targets", file)
assertNotNil(os.MkdirAll(filepath.Dir(path), 0755))
assertNotNil(ioutil.WriteFile(path, data, 0644))
assertNoError(os.MkdirAll(filepath.Dir(path), 0755))
assertNoError(ioutil.WriteFile(path, data, 0644))
paths = append(paths, file)
}
assertNotNil(repo.AddTargetsWithExpires(paths, nil, expirationDate))
assertNoError(repo.AddTargetsWithExpires(paths, nil, expirationDate))
}

func revokeKeys(repo *tuf.Repo, role string, keyList []*data.PrivateKey) {
for _, key := range keyList {
signer, err := keys.GetSigner(key)
assertNotNil(err)
assertNotNil(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
assertNoError(err)
assertNoError(repo.RevokeKeyWithExpires(role, signer.PublicData().IDs()[0], expirationDate))
}
}

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

func Generate(dir string, keysPath string, consistentSnapshot bool) {
f, err := os.Open(keysPath)
assertNotNil(err)
assertNoError(err)

var roleKeys map[string][][]*data.PrivateKey
assertNotNil(json.NewDecoder(f).Decode(&roleKeys))
assertNoError(json.NewDecoder(f).Decode(&roleKeys))

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

Expand Down
6 changes: 3 additions & 3 deletions client/testdata/tools/gen-keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ func main() {

for i := 0; i < 2; i++ {
signer, err := keys.GenerateEd25519Key()
assertNotNil(err)
assertNoError(err)
keys = append(keys, []*data.PrivateKey{signer})
}

roles[name] = keys
}

s, err := json.MarshalIndent(&roles, "", " ")
assertNotNil(err)
assertNoError(err)

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

func assertNotNil(err error) {
func assertNoError(err error) {
if err != nil {
panic(fmt.Sprintf("assertion failed: %s", err))
}
Expand Down