You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/agent/metadata/build_test.go

76 lines
1.2 KiB

package metadata
import (
"testing"
"github.com/hashicorp/go-version"
"github.com/hashicorp/serf/serf"
"github.com/pascaldekloe/goe/verify"
)
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)
}
verify.Values(t, "", ver, tt.ver)
})
}
}