refactor: make internals easier to test and add unit tests (#2)
This PR refactors most of the internals to make them easier to test (and also because the names didn't make sense). It adds unit tests for all internal components. Reviewed-on: #2 Co-authored-by: Emmanuel BENOÎT <tseeker@nocternity.net> Co-committed-by: Emmanuel BENOÎT <tseeker@nocternity.net>
This commit is contained in:
parent
dcd732cc34
commit
78af496fe9
20 changed files with 939 additions and 369 deletions
pkg/version
31
pkg/version/version_test.go
Normal file
31
pkg/version/version_test.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package version // import nocternity.net/gomonop/pkg/version
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
type Test struct {
|
||||
version, commit, status, target, expected string
|
||||
}
|
||||
|
||||
tests := []Test{
|
||||
{"", "COMMIT", "clean", "TARGET", "development version (COMMIT) TARGET"},
|
||||
{"VERSION", "COMMIT", "clean", "TARGET", "VERSION (COMMIT) TARGET"},
|
||||
{"", "COMMIT", "dirty", "TARGET", "development version (COMMIT*) TARGET"},
|
||||
{"VERSION", "COMMIT", "dirty", "TARGET", "VERSION (COMMIT*) TARGET"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
version = test.version
|
||||
commit = test.commit
|
||||
status = test.status
|
||||
target = test.target
|
||||
|
||||
result := Version()
|
||||
|
||||
assert.Equal(t, test.expected, result, "Expected '%s', got '%s'", test.expected, result)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue