blob: 447de1d3c9c2e275b4c996d4eaab4566dd72b5e2 [file] [log] [blame]
Jungho Ahna23cd222015-08-31 18:58:16 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package discovery_test
6
7import (
8 "testing"
9
Jungho Ahn4ef9e252015-09-15 16:54:33 -070010 "v.io/x/ref/lib/discovery"
Jungho Ahna23cd222015-08-31 18:58:16 -070011)
12
13func TestServiceUUID(t *testing.T) {
14 tests := []struct {
15 in, want string
16 }{
17 {"v.io", "2101363c-688d-548a-a600-34d506e1aad0"},
18 {"v.io/v23/abc", "6726c4e5-b6eb-5547-9228-b2913f4fad52"},
19 {"v.io/v23/abc/xyz", "be8a57d7-931d-5ee4-9243-0bebde0029a5"},
20 }
21
22 for _, test := range tests {
23 if got := discovery.NewServiceUUID(test.in).String(); got != test.want {
24 t.Errorf("ServiceUUID for %q mismatch; got %q, want %q", test.in, got, test.want)
25 }
26 }
27}
28
29func TestInstanceUUID(t *testing.T) {
30 uuids := make(map[string]struct{})
31 for x := 0; x < 100; x++ {
32 uuid := discovery.NewInstanceUUID().String()
33 if _, ok := uuids[uuid]; ok {
34 t.Errorf("InstanceUUID returned duplicated UUID %q", uuid)
35 }
36 uuids[uuid] = struct{}{}
37 }
38}