forked from owlwalks/rind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_test.go
50 lines (46 loc) · 1.11 KB
/
store_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
// Copyright 2018 The Rind Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rind
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"golang.org/x/net/dns/dnsmessage"
)
func Test_store_save_load(t *testing.T) {
dirPath, err := ioutil.TempDir("", "")
if err != nil {
t.Skip(err)
}
name, _ := dnsmessage.NewName("test")
data := map[string]entry{
"test": {
Resources: []dnsmessage.Resource{
{
Header: dnsmessage.ResourceHeader{
Name: name,
Type: dnsmessage.TypeA,
Class: dnsmessage.ClassINET,
},
Body: &dnsmessage.AResource{A: [4]byte{127, 0, 0, 1}},
},
},
},
}
book := store{data: data, rwDirPath: dirPath}
book.save()
main, _ := os.Stat(filepath.Join(dirPath, storeName))
bk, _ := os.Stat(filepath.Join(dirPath, storeBkName))
if main.Size() != 664 || bk.Size() != 0 {
t.Fail()
}
bookNew := store{rwDirPath: dirPath}
bookNew.load()
r, _ := bookNew.get("test")
body, _ := r[0].Body.(*dnsmessage.AResource)
if body.A != [4]byte{127, 0, 0, 1} {
t.Fail()
}
}