Skip to content

Commit

Permalink
add strict NewWithNamespace tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoly-kussul committed Jan 6, 2025
1 parent b6e5b1a commit cdc336f
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions shortuuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,29 @@ var testVector = []struct {
{"f9ee01c3-2015-4716-930e-4d5449810833", "nUfojcH2M5j9j3Tk5A8mf7"},
}

func TestGeneration(t *testing.T) {
tests := []string{
"",
"http://www.example.com/",
"HTTP://www.example.com/",
"example.com/",
func TestNewWithNamespace(t *testing.T) {
var tests = []struct {
name string
uuid string
}{
{"http://www.example.com/", "nzUQAfy7CW4Dd4kzLguPSV"},
{"HTTP://www.example.com/", "N9ZezvXJcoXvKzwiNmGYmH"},
{"Https://www.example.com/", "jSz34Z6QzADzy93ywucXMv"},
{"example.com/", "kueUMiGUbGccYhpZK8Czat"},
{"うえおなにぬねのウエオナニヌネノうえおなにぬねのウエオナニヌネノ", "Mp2Q7GQSRYnoDZyCtGttDg"},
{"う", "dTbaUbVKrhNkkZKEwZxLqa"},
}

for _, test := range tests {
u := NewWithNamespace(test)
if len(u) < 20 || len(u) > 24 {
t.Errorf("expected %q to be in range [20, 24], got %d", u, len(u))
u := NewWithNamespace(test.name)

if u != test.uuid {
t.Errorf("expected %q, got %q", test.uuid, u)
}
}

if NewWithNamespace("") == NewWithNamespace("") {

Check failure on line 151 in shortuuid_test.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 1.21)

SA4000: identical expressions on the left and right side of the '==' operator (staticcheck)

Check failure on line 151 in shortuuid_test.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.21)

SA4000: identical expressions on the left and right side of the '==' operator (staticcheck)
t.Errorf("NewWithNamespace should generate random uuid with empty namespace")
}
}

func TestEncoding(t *testing.T) {
Expand Down

0 comments on commit cdc336f

Please sign in to comment.