Skip to content

Commit

Permalink
test: add validate Go package test
Browse files Browse the repository at this point in the history
  • Loading branch information
kare committed Sep 15, 2024
1 parent d867a49 commit 287926d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions vanity_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package vanity

import "testing"

func TestValidateGoPackage(t *testing.T) {
tests := []struct {
name string
pkg string
wantErr bool
}{
{
name: "all allowed characters",
pkg: "/foo/bar/123/foo_abc",
wantErr: false,
},
{
name: "contains query",
pkg: "/foobar?go-get=1",
wantErr: false,
},
{
name: "contains dot",
pkg: "/foo.bar",
wantErr: false,
},
{
name: "contains minus",
pkg: "/foo-bar",
wantErr: false,
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()

if err := validateGoPkgPath(test.pkg); (err != nil) != test.wantErr {
t.Errorf("expecting error, none reported. error: %v", err)
}
})
}
}

0 comments on commit 287926d

Please sign in to comment.