blob: 3fe95db0fb124c402c6fb9e9f3274c0f66f2804d [file] [log] [blame]
Shyam Jayaraman22b3b992015-09-25 11:51:50 -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 ble
6
7import (
Shyam Jayaraman22b3b992015-09-25 11:51:50 -07008 "reflect"
9 "testing"
Jungho Ahnc3cfceb2015-09-28 14:56:20 -070010
11 "github.com/pborman/uuid"
12
Shyam Jayaraman22b3b992015-09-25 11:51:50 -070013 vdiscovery "v.io/v23/discovery"
Jungho Ahnc3cfceb2015-09-28 14:56:20 -070014
Shyam Jayaraman22b3b992015-09-25 11:51:50 -070015 "v.io/x/ref/lib/discovery"
16)
17
18func TestConvertingBackAndForth(t *testing.T) {
19 v23Adv := discovery.Advertisement{
20 Service: vdiscovery.Service{
Jungho Ahnc3cfceb2015-09-28 14:56:20 -070021 InstanceUuid: []byte(discovery.NewInstanceUUID()),
22 Attrs: vdiscovery.Attributes{
Shyam Jayaraman22b3b992015-09-25 11:51:50 -070023 "key1": "value1",
24 "key2": "value2",
25 },
Jungho Ahnc3cfceb2015-09-28 14:56:20 -070026 Addrs: []string{"localhost:1000", "example.com:540"},
Shyam Jayaraman22b3b992015-09-25 11:51:50 -070027 },
Jungho Ahnc3cfceb2015-09-28 14:56:20 -070028 ServiceUuid: uuid.NewUUID(),
29 EncryptionAlgorithm: discovery.TestEncryption,
30 EncryptionKeys: []discovery.EncryptionKey{discovery.EncryptionKey("k1"), discovery.EncryptionKey("k2")},
Shyam Jayaraman22b3b992015-09-25 11:51:50 -070031 }
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}