Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -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 ble |
| 6 | |
| 7 | import ( |
Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -0700 | [diff] [blame] | 8 | "reflect" |
| 9 | "testing" |
Jungho Ahn | c3cfceb | 2015-09-28 14:56:20 -0700 | [diff] [blame] | 10 | |
| 11 | "github.com/pborman/uuid" |
| 12 | |
Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -0700 | [diff] [blame] | 13 | vdiscovery "v.io/v23/discovery" |
Jungho Ahn | c3cfceb | 2015-09-28 14:56:20 -0700 | [diff] [blame] | 14 | |
Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -0700 | [diff] [blame] | 15 | "v.io/x/ref/lib/discovery" |
| 16 | ) |
| 17 | |
| 18 | func TestConvertingBackAndForth(t *testing.T) { |
| 19 | v23Adv := discovery.Advertisement{ |
| 20 | Service: vdiscovery.Service{ |
Jungho Ahn | c3cfceb | 2015-09-28 14:56:20 -0700 | [diff] [blame] | 21 | InstanceUuid: []byte(discovery.NewInstanceUUID()), |
| 22 | Attrs: vdiscovery.Attributes{ |
Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -0700 | [diff] [blame] | 23 | "key1": "value1", |
| 24 | "key2": "value2", |
| 25 | }, |
Jungho Ahn | c3cfceb | 2015-09-28 14:56:20 -0700 | [diff] [blame] | 26 | Addrs: []string{"localhost:1000", "example.com:540"}, |
Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -0700 | [diff] [blame] | 27 | }, |
Jungho Ahn | c3cfceb | 2015-09-28 14:56:20 -0700 | [diff] [blame] | 28 | ServiceUuid: uuid.NewUUID(), |
| 29 | EncryptionAlgorithm: discovery.TestEncryption, |
| 30 | EncryptionKeys: []discovery.EncryptionKey{discovery.EncryptionKey("k1"), discovery.EncryptionKey("k2")}, |
Shyam Jayaraman | 22b3b99 | 2015-09-25 11:51:50 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | adv := newAdvertisment(v23Adv) |
| 34 | out, err := adv.toDiscoveryAdvertisement() |
| 35 | if err != nil { |
| 36 | t.Errorf("unexpected error: %v", err) |
| 37 | } |
| 38 | |
| 39 | if !reflect.DeepEqual(&v23Adv, out) { |
| 40 | t.Errorf("input does not equal output: %v, %v", v23Adv, out) |
| 41 | } |
| 42 | } |