1
0
forked from sm/vain
vain/vain_test.go

97 lines
1.6 KiB
Go
Raw Normal View History

2016-02-11 11:57:16 -08:00
package vain
2016-02-07 23:54:55 -08:00
import (
"fmt"
"testing"
)
func TestString(t *testing.T) {
2016-02-08 00:14:30 -08:00
p := Package{
2016-02-15 01:10:14 -08:00
path: "mcquay.me/bps",
2016-02-07 23:54:55 -08:00
Repo: "https://s.mcquay.me/sm/bps",
}
got := fmt.Sprintf("%s", p)
want := `<meta name="go-import" content="mcquay.me/bps git https://s.mcquay.me/sm/bps">`
if got != want {
t.Errorf(
"incorrect converstion to meta; got %s, want %s",
got,
want,
)
}
}
func TestVcsStrings(t *testing.T) {
tests := []struct {
got string
want string
}{
{fmt.Sprintf("%+v", Git), "git"},
{fmt.Sprintf("%+v", Hg), "mercurial"},
2016-02-16 18:32:04 -08:00
{fmt.Sprintf("%+v", Svn), "svn"},
{fmt.Sprintf("%+v", Bzr), "bazaar"},
2016-02-07 23:54:55 -08:00
}
for _, test := range tests {
if test.got != test.want {
2016-02-11 11:57:16 -08:00
t.Errorf("incorrect conversion of vain.Vcs -> string; got %q, want %q", test.got, test.want)
2016-02-07 23:54:55 -08:00
}
}
}
func TestValid(t *testing.T) {
tests := []struct {
pkgs []Package
in string
want bool
}{
{
pkgs: []Package{},
in: "bobo",
want: true,
},
{
pkgs: []Package{
2016-02-15 01:10:14 -08:00
{path: ""},
},
in: "bobo",
want: true,
},
{
pkgs: []Package{
2016-02-15 01:10:14 -08:00
{path: "bobo"},
},
in: "bobo",
want: false,
},
{
pkgs: []Package{
2016-02-15 01:10:14 -08:00
{path: "a/b/c"},
},
in: "a/b/c",
want: false,
},
{
pkgs: []Package{
2016-02-15 01:10:14 -08:00
{path: "foo/bar"},
{path: "foo/baz"},
},
in: "foo",
want: false,
},
{
pkgs: []Package{
2016-02-15 01:10:14 -08:00
{path: "bilbo"},
{path: "frodo"},
},
in: "foo/bar/baz",
want: true,
},
}
for _, test := range tests {
got := Valid(test.in, test.pkgs)
if got != test.want {
t.Errorf("Incorrect testing of %q against %#v; got %t, want %t", test.in, test.pkgs, got, test.want)
}
}
}