Skip to content

Commit

Permalink
Convert Version struct tests to use assert lib
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmachado committed Jun 16, 2018
1 parent d408cc7 commit 4a864c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
2 changes: 1 addition & 1 deletion chg/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestChangelogVersion(t *testing.T) {

t.Run("version=unknown", func(t *testing.T) {
result := c.Version("unknown")
assert.NotNil(t, result)
assert.Nil(t, result)
})
}

Expand Down
39 changes: 11 additions & 28 deletions chg/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package chg

import (
"bytes"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSortChanges(t *testing.T) {
Expand All @@ -30,9 +31,7 @@ func TestSortChanges(t *testing.T) {

v.SortChanges()

if !reflect.DeepEqual(v.Changes, expected) {
t.Error("SortChanges should sort Changes properly")
}
assert.Equal(t, expected, v.Changes)
}

func TestChange(t *testing.T) {
Expand All @@ -49,16 +48,12 @@ func TestChange(t *testing.T) {

t.Run("change-exists", func(t *testing.T) {
result := v.Change(Added)
if result != added {
t.Errorf("Search for change, expected %s got %s", Added, result)
}
assert.Equal(t, added, result)
})

t.Run("change-does-not-exist", func(t *testing.T) {
result := v.Change(Security)
if result != nil {
t.Errorf("Search for unknown change, expected nil got %s", result)
}
assert.Nil(t, result)
})
}

Expand All @@ -71,9 +66,7 @@ func TestRenderTitle(t *testing.T) {
var buf bytes.Buffer
v.RenderTitle(&buf)
result := string(buf.Bytes())
if expected != result {
t.Errorf("RenderTitle should render version only, expected %s, got %s", expected, result)
}
assert.Equal(t, expected, result)
})

t.Run("date", func(t *testing.T) {
Expand All @@ -85,9 +78,7 @@ func TestRenderTitle(t *testing.T) {
var buf bytes.Buffer
v.RenderTitle(&buf)
result := string(buf.Bytes())
if expected != result {
t.Errorf("RenderTitle should render the date, expected %s, got %s", expected, result)
}
assert.Equal(t, expected, result)
})

t.Run("link", func(t *testing.T) {
Expand All @@ -99,9 +90,7 @@ func TestRenderTitle(t *testing.T) {
var buf bytes.Buffer
v.RenderTitle(&buf)
result := string(buf.Bytes())
if expected != result {
t.Errorf("RenderTitle should render link, expected %s, got %s", expected, result)
}
assert.Equal(t, expected, result)
})

t.Run("yanked", func(t *testing.T) {
Expand All @@ -113,9 +102,7 @@ func TestRenderTitle(t *testing.T) {
var buf bytes.Buffer
v.RenderTitle(&buf)
result := string(buf.Bytes())
if expected != result {
t.Errorf("RenderTitle should render yanked versions, expected %s, got %s", expected, result)
}
assert.Equal(t, expected, result)
})
}

Expand Down Expand Up @@ -152,9 +139,7 @@ func TestRenderChanges(t *testing.T) {
v.RenderChanges(&buf)
result := string(buf.Bytes())

if result != expected {
t.Errorf("RenderChanges fail, expected %s got %s", expected, result)
}
assert.Equal(t, expected, result)
}

func TestVersionRender(t *testing.T) {
Expand Down Expand Up @@ -191,7 +176,5 @@ func TestVersionRender(t *testing.T) {
v.Render(&buf)
result := string(buf.Bytes())

if result != expected {
t.Errorf("RenderChanges fail, expected %s got %s", expected, result)
}
assert.Equal(t, expected, result)
}

0 comments on commit 4a864c0

Please sign in to comment.