Skip to content

Commit

Permalink
Fix unit tests error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-yurchenko committed Jul 9, 2023
1 parent 58be836 commit 40a2625
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
22 changes: 10 additions & 12 deletions changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,8 @@ func TestSaveToFile(t *testing.T) {
}

err := test.Changelog.SaveToFile(m, "CHANGELOG.md")
if test.Expected != "" {
if test.Expected != "" || err != nil {
a.EqualError(err, fmt.Sprintf("error creating a file: %v", test.Expected))
} else {
a.Equal(nil, err)
}
}
}
Expand Down Expand Up @@ -352,10 +350,10 @@ func TestSetUnreleasedURL(t *testing.T) {
counter++
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

if test.Expected != "" {
a.EqualError(test.Changelog.SetUnreleasedURL(test.URL), test.Expected)
} else {
a.Equal(nil, test.Changelog.SetUnreleasedURL(test.URL))
err := test.Changelog.SetUnreleasedURL(test.URL)

if test.Expected != "" || err != nil {
a.EqualError(err, test.Expected)
}
}
}
Expand Down Expand Up @@ -438,7 +436,7 @@ func TestAddUnreleasedChange(t *testing.T) {

err := test.Changelog.AddUnreleasedChange(test.Scope, test.Change)

if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Changelog, test.Changelog)
Expand Down Expand Up @@ -530,7 +528,7 @@ func TestChangelogCreateRelease(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

r, err := test.Changelog.CreateRelease(test.Version, test.Date)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Release, r)
Expand Down Expand Up @@ -584,7 +582,7 @@ func TestChangelogCreateReleaseWithURL(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

r, err := test.Changelog.CreateReleaseWithURL(test.Version, test.Date, test.URL)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Release, r)
Expand Down Expand Up @@ -681,7 +679,7 @@ func TestCreateReleaseFromUnreleased(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

r, err := test.Changelog.CreateReleaseFromUnreleased(test.Version, test.Date)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Release, r)
Expand Down Expand Up @@ -789,7 +787,7 @@ func TestCreateReleaseFromUnreleasedWithURL(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

r, err := test.Changelog.CreateReleaseFromUnreleasedWithURL(test.Version, test.Date, test.URL)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Release, r)
Expand Down
2 changes: 1 addition & 1 deletion changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func TestAddChange(t *testing.T) {

err := test.Changes.AddChange(test.Scope, test.Change)
a.Equal(test.Expected.Changes, test.Changes)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
}
}
Expand Down
12 changes: 3 additions & 9 deletions release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,8 @@ func TestSetDate(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

err := test.Release.SetDate(test.Date)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(nil, err)
}
}
}
Expand Down Expand Up @@ -192,10 +190,8 @@ func TestSetVersion(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

err := test.Release.SetVersion(test.Version)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(nil, err)
}
}
}
Expand Down Expand Up @@ -241,10 +237,8 @@ func TestSetURL(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

err := test.Release.SetURL(test.URL)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(nil, err)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestReleasesCreateRelease(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

r, err := test.Releases.CreateRelease(test.Version, test.Date)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Release, r)
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestReleasesCreateReleaseWithURL(t *testing.T) {
t.Logf("Test Case %v/%v - %s", counter, len(suite), name)

r, err := test.Releases.CreateReleaseWithURL(test.Version, test.Date, test.URL)
if test.Expected.Error != "" {
if test.Expected.Error != "" || err != nil {
a.EqualError(err, test.Expected.Error)
} else {
a.Equal(test.Expected.Release, r)
Expand Down

0 comments on commit 40a2625

Please sign in to comment.