This repository was archived by the owner on Sep 20, 2024. It is now read-only.
forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnns_test.go
108 lines (97 loc) · 2.59 KB
/
nns_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package nns
import (
"context"
"testing"
"github.com/coredns/coredns/plugin/nns/contract"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
"github.com/stretchr/testify/require"
)
func TestGetNetmapHash(t *testing.T) {
ctx := context.Background()
container := createDockerContainer(ctx, t, testImage)
defer container.Terminate(ctx)
prm := &contract.Params{
Endpoint: "http://localhost:30333",
}
nnsContract, err := contract.NewContract(ctx, prm)
require.NoError(t, err)
nns := NNS{
Next: test.NextHandler(dns.RcodeSuccess, nil),
Contracts: []*contract.Contract{nnsContract},
}
req := new(dns.Msg)
req.SetQuestion(dns.Fqdn("netmap.neofs"), dns.TypeTXT)
req.Question[0].Qclass = dns.ClassCHAOS
rec := dnstest.NewRecorder(&test.ResponseWriter{})
status, err := nns.ServeDNS(context.TODO(), rec, req)
require.NoError(t, err)
require.Equal(t, dns.RcodeSuccess, status)
res := rec.Msg.Answer[0].(*dns.TXT).Txt[0]
require.Equal(t, "0605a9623cb07b638fc6fe243bb7dc8bc50d30cd", res)
t.Run("prepare names", func(t *testing.T) {
for _, tc := range []struct {
dnsDomain string
nnsDomain string
request string
expected string
}{
{
dnsDomain: ".",
nnsDomain: "",
request: "test.neofs",
expected: "test.neofs",
},
{
dnsDomain: ".",
nnsDomain: "",
request: "test.neofs.",
expected: "test.neofs",
},
{
dnsDomain: ".",
nnsDomain: "container.",
request: "test.neofs",
expected: "test.neofs.container",
},
{
dnsDomain: ".",
nnsDomain: ".container",
request: "test.neofs.",
expected: "test.neofs.container",
},
{
dnsDomain: "containers.testnet.fs.neo.org.",
nnsDomain: "container",
request: "containers.testnet.fs.neo.org",
expected: "container",
},
{
dnsDomain: ".containers.testnet.fs.neo.org",
nnsDomain: "container",
request: "containers.testnet.fs.neo.org.",
expected: "container",
},
{
dnsDomain: "containers.testnet.fs.neo.org.",
nnsDomain: "container",
request: "nicename.containers.testnet.fs.neo.org",
expected: "nicename.container",
},
} {
t.Run("", func(t *testing.T) {
nnsPlugin := &NNS{}
nnsPlugin.setDNSDomain(tc.dnsDomain)
contractPrm := &contract.Params{
Endpoint: prm.Endpoint,
Domain: tc.nnsDomain,
}
contractNNS, err := contract.NewContract(ctx, contractPrm)
require.NoError(t, err)
result := contractNNS.PrepareName(tc.request, nnsPlugin.dnsDomain)
require.Equal(t, tc.expected, result)
})
}
})
}