Exemple #1
0
// Verifies that Variant5() produces consistent results for a given name space
// and name.
func TestVariant5(t *testing.T) {
	same1 := uuid.Variant5(uuid.NameSpaceDNS(), "some-name")
	same2 := uuid.Variant5(uuid.NameSpaceDNS(), "some-name")
	other_name := uuid.Variant5(uuid.NameSpaceDNS(), "some-other-name")
	other_domain := uuid.Variant5(uuid.NameSpaceX500(), "some-name")

	if same1.String() != "33d1b922-4cf2-566d-a20a-bc0f77f14de7" {
		t.Fatal("UUID generation for 'some-name' doesn't match known output.")
	}

	if !same1.Equal(same2) {
		t.Fatal("UUID generation for 'some-name' is not the same.")
	}

	if same1.Equal(other_name) {
		t.Fatal("UUID generation for 'some-other-name' were the same.")
	}

	if same1.Equal(other_domain) {
		t.Fatal("UUID generation for 'some-name' in other domain not different..")
	}
}
Exemple #2
0
// Benchmarks the Variant5() UUIDs.
func BenchmarkVariant5(b *testing.B) {
	u := uuid.NameSpaceURL()
	for i := 0; i < b.N; i++ {
		uuid.Variant5(u, "http://apcera.com/uuidtest_url_demo_url")
	}
}