e8a883e829
* testing: replace most goe/verify.Values with require.Equal One difference between these two comparisons is that go/verify considers nil slices/maps to be equal to empty slices/maps, where as testify/require does not, and does not appear to provide any way to enable that behaviour. Because of this difference some expected values were changed from empty slices to nil slices, and some calls to verify.Values were left. * Remove github.com/pascaldekloe/goe/verify Reduce the number of assertion packages we use from 2 to 1
76 lines
1.2 KiB
Go
76 lines
1.2 KiB
Go
package metadata
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
"github.com/hashicorp/serf/serf"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBuild(t *testing.T) {
|
|
tests := []struct {
|
|
desc string
|
|
m *serf.Member
|
|
ver *version.Version
|
|
err bool
|
|
}{
|
|
{
|
|
"no version",
|
|
&serf.Member{},
|
|
nil,
|
|
true,
|
|
},
|
|
{
|
|
"bad version",
|
|
&serf.Member{
|
|
Tags: map[string]string{
|
|
"build": "nope",
|
|
},
|
|
},
|
|
nil,
|
|
true,
|
|
},
|
|
{
|
|
"good version",
|
|
&serf.Member{
|
|
Tags: map[string]string{
|
|
"build": "0.8.5",
|
|
},
|
|
},
|
|
version.Must(version.NewVersion("0.8.5")),
|
|
false,
|
|
},
|
|
{
|
|
"rc version",
|
|
&serf.Member{
|
|
Tags: map[string]string{
|
|
"build": "0.9.3rc1:d62743c",
|
|
},
|
|
},
|
|
version.Must(version.NewVersion("0.9.3")),
|
|
false,
|
|
},
|
|
{
|
|
"ent version",
|
|
&serf.Member{
|
|
Tags: map[string]string{
|
|
"build": "0.9.3+ent:d62743c",
|
|
},
|
|
},
|
|
version.Must(version.NewVersion("0.9.3")),
|
|
false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.desc, func(t *testing.T) {
|
|
ver, err := Build(tt.m)
|
|
gotErr := err != nil
|
|
if wantErr := tt.err; gotErr != wantErr {
|
|
t.Fatalf("got %v want %v", gotErr, wantErr)
|
|
}
|
|
require.Equal(t, tt.ver, ver)
|
|
})
|
|
}
|
|
}
|