Пример #1
0
// Benchmark the FromString() function.
func BenchmarkFromString(b *testing.B) {
	// Generate a UUID outside of the timer.
	b.StopTimer()
	u := uuid.Variant1().String()
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		uuid.FromString(u)
	}
}
Пример #2
0
// End to end test, generate, then convert to string, then UUID and back and
// verify that it comes out looking correct.
func TestEndToEndConversion(t *testing.T) {
	initial := uuid.Variant1()
	to_string := initial.String()
	from_string, err := uuid.FromString(to_string)
	if err != nil {
		t.Fatal("Parsing error for an unknown reason: " + err.Error())
	}

	if !initial.Equal(from_string) {
		t.Fatal("Result of Variant1() -> String() -> FromString are not equal.")
	}
}
Пример #3
0
// Test to make sure that FromString works by testing a good string as well
// as a few bad ones.
func TestFromString(t *testing.T) {
	s_valid := "01234567-890a-1bcd-af01-234567890abc"
	if _, err := uuid.FromString(s_valid); err != nil {
		t.Fatal("Failed to parse a valid UUID: " + s_valid + " error: " +
			err.Error())
	}

	s_invalid_len := "123456789abcdef"
	if _, err := uuid.FromString(s_invalid_len); err == nil {
		t.Fatal("Failed to detect a short UUID: " + s_invalid_len)
	}

	s_invalid_dash := "01234567f890af1bcdfef01f234567890abc"
	if _, err := uuid.FromString(s_invalid_dash); err == nil {
		t.Fatal("Failed to detect an invalid UUID: " + s_invalid_dash)
	}

	s_reserved_bits := "01234567-890a-1bcd-ef01-234567890abc"
	if _, err := uuid.FromString(s_reserved_bits); err == nil {
		t.Fatal("Failed to detect an invalid UUID: " + s_invalid_dash)
	}
}