Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use uuid.MustParse() to simplify test setup #62

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions shortuuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ func TestGeneration(t *testing.T) {

func TestEncoding(t *testing.T) {
for _, test := range testVector {
u, err := uuid.Parse(test.uuid)
if err != nil {
t.Error(err)
}

u := uuid.MustParse(test.uuid)
suuid := DefaultEncoder.Encode(u)

if suuid != test.shortuuid {
Expand All @@ -161,10 +157,7 @@ func TestEncoding(t *testing.T) {

func TestDecoding(t *testing.T) {
for _, test := range testVector {
u1, err := uuid.Parse(test.uuid)
if err != nil {
t.Error(err)
}
u1 := uuid.MustParse(test.uuid)

u2, err := DefaultEncoder.Decode(test.shortuuid)
if err != nil {
Expand Down Expand Up @@ -202,7 +195,7 @@ func TestDecodingErrors(t *testing.T) {
func TestNewWithAlphabet(t *testing.T) {
abc := DefaultAlphabet[:len(DefaultAlphabet)-1] + "="
enc := encoder{newAlphabet(abc)}
u1, _ := uuid.Parse("e9ae9ba7-4fb1-4a6d-bbca-5315ed438371")
u1 := uuid.MustParse("e9ae9ba7-4fb1-4a6d-bbca-5315ed438371")
u2 := enc.Encode(u1)
if u2 != "iZsai==fWebXd5rLRWFB=u" {
t.Errorf("expected uuid to be %q, got %q", "u=BFWRLr5dXbeWf==iasZi", u2)
Expand All @@ -212,7 +205,7 @@ func TestNewWithAlphabet(t *testing.T) {
func TestNewWithAlphabet_MultipleBytes(t *testing.T) {
abc := DefaultAlphabet[:len(DefaultAlphabet)-2] + "おネ"
enc := encoder{newAlphabet(abc)}
u1, _ := uuid.Parse("e9ae9ba7-4fb1-4a6d-bbca-5315ed438374")
u1 := uuid.MustParse("e9ae9ba7-4fb1-4a6d-bbca-5315ed438374")
u2 := enc.Encode(u1)
if u2 != "jatbjAAgXfcYe5sMSXGCAお" {
t.Errorf("expected uuid to be %q, got %q", "jatbjAAgXfcYe5sMSXGCAお", u2)
Expand All @@ -222,7 +215,7 @@ func TestNewWithAlphabet_MultipleBytes(t *testing.T) {
func TestAlphabetCustomLen(t *testing.T) {
abc := "21345687654123456"
enc := encoder{newAlphabet(abc)}
u1, _ := uuid.Parse("13ef31aa-934b-4f37-93b3-6e3ef30148e2")
u1 := uuid.MustParse("13ef31aa-934b-4f37-93b3-6e3ef30148e2")
exp := "1348474176355756628268227744454847411355453"
u2 := enc.Encode(u1)
if u2 != exp {
Expand All @@ -242,7 +235,7 @@ func TestAlphabetCustomLen(t *testing.T) {
func TestAlphabet_MB(t *testing.T) {
abc := "うえおなにぬねのウエオナニヌネノ"
enc := encoder{newAlphabet(abc)}
u1, _ := uuid.Parse("13ef31aa-934b-4f37-93b3-6e3ef30148e2")
u1 := uuid.MustParse("13ef31aa-934b-4f37-93b3-6e3ef30148e2")
exp := "えなネノなえオオエなにナにノなのエなナなねネなネノなうえにウネお"
u2 := enc.Encode(u1)
if u2 != exp {
Expand Down
Loading