forked from brutella/hc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
85 lines (67 loc) · 1.58 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package hc
import (
"reflect"
"testing"
"github.com/brutella/hc/util"
)
var config = &Config{
name: "My MDNS Service",
id: "1234",
servePort: 5010,
version: 1,
categoryId: 1,
state: 1,
protocol: "1.0",
discoverable: true,
mfiCompliant: false,
}
func TestTxtRecords(t *testing.T) {
expect := map[string]string{
"pv": "1.0",
"id": "1234",
"c#": "1",
"s#": "1",
"sf": "0",
"ff": "0",
"md": "My MDNS Service",
"ci": "1",
"sh": "1ARVnw==",
}
config.discoverable = false
if x := config.txtRecords(); reflect.DeepEqual(x, expect) == false {
t.Fatalf("%v != %v", x, expect)
}
}
func TestVersionUpdate(t *testing.T) {
storage, err := util.NewTempFileStorage()
if err != nil {
t.Fatal(err)
}
storage.Set("configHash", []byte("AB"))
storage.Set("version", []byte("1"))
config.load(storage)
config.updateConfigHash([]byte("ABC"))
config.save(storage)
if x := config.version; x != 2 {
t.Fatal(x)
}
if x, _ := storage.Get("configHash"); reflect.DeepEqual(x, config.configHash) == false {
t.Fatal(string(x))
}
if x, _ := storage.Get("version"); reflect.DeepEqual(x, []byte("2")) == false {
t.Fatal(string(x))
}
}
func TestSetupID(t *testing.T) {
expected := "1ARVnw=="
hash := config.setupHash()
if hash != expected {
t.Fatalf("generated setup hash is not identical (actual: %s, expected: %s)", hash, expected)
}
config.SetupId = "UPDT"
expected = "PrXxQA=="
hash = config.setupHash()
if hash != expected {
t.Fatalf("generated setup hash is not identical (actual: %s, expected: %s)", hash, expected)
}
}