1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
package atlas
import (
"strings"
"testing"
)
func TestParseSlug_emptyString(t *testing.T) {
_, _, err := ParseSlug("")
if err == nil {
t.Fatal("expected error, but nothing was returned")
}
expected := "missing slug"
if !strings.Contains(err.Error(), expected) {
t.Fatalf("expected %q to contain %q", err.Error(), expected)
}
}
func TestParseSlug_noSlashes(t *testing.T) {
_, _, err := ParseSlug("bacon")
if err == nil {
t.Fatal("expected error, but nothing was returned")
}
expected := "malformed slug"
if !strings.Contains(err.Error(), expected) {
t.Fatalf("expected %q to contain %q", err.Error(), expected)
}
}
func TestParseSlug_multipleSlashes(t *testing.T) {
_, _, err := ParseSlug("bacon/is/delicious/but/this/is/not/valid")
if err == nil {
t.Fatal("expected error, but nothing was returned")
}
expected := "malformed slug"
if !strings.Contains(err.Error(), expected) {
t.Fatalf("expected %q to contain %q", err.Error(), expected)
}
}
func TestParseSlug_goodString(t *testing.T) {
user, name, err := ParseSlug("hashicorp/project")
if err != nil {
t.Fatal(err)
}
if user != "hashicorp" {
t.Fatalf("expected %q to be %q", user, "hashicorp")
}
if name != "project" {
t.Fatalf("expected %q to be %q", name, "project")
}
}
|