Jungho Ahn | a23cd22 | 2015-08-31 18:58:16 -0700 | [diff] [blame] | 1 | // 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 | |
| 5 | package discovery_test |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | |
Jungho Ahn | 4ef9e25 | 2015-09-15 16:54:33 -0700 | [diff] [blame] | 10 | "v.io/x/ref/lib/discovery" |
Jungho Ahn | a23cd22 | 2015-08-31 18:58:16 -0700 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func 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 | |
| 29 | func 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 | } |