forked from nbd-wtf/go-nostr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnip05_test.go
56 lines (50 loc) · 1.58 KB
/
nip05_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
package nip05
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParse(t *testing.T) {
tests := []struct {
input string
expectedName string
expectedDomain string
expectError bool
}{
{"[email protected]", "saknd", "yyq.com", false},
{"287354gkj+asbdfo8gw3rlicbsopifbcp3iougb5piseubfdikswub5ks@yyq.com", "287354gkj+asbdfo8gw3rlicbsopifbcp3iougb5piseubfdikswub5ks", "yyq.com", false},
{"asdn.com", "_", "asdn.com", false},
{"[email protected]", "_", "uxux.com.br", false},
{"821yh498ig21", "", "", true},
{"////", "", "", true},
}
for _, test := range tests {
name, domain, err := ParseIdentifier(test.input)
if test.expectError {
assert.Error(t, err, "expected error for input: %s", test.input)
} else {
assert.NoError(t, err, "not expect error for input: %s", test.input)
assert.Equal(t, test.expectedName, name)
assert.Equal(t, test.expectedDomain, domain)
}
}
}
func TestQuery(t *testing.T) {
tests := []struct {
input string
expectedKey string
expectError bool
}{
{"fiatjaf.com", "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d", false},
{"[email protected]", "f9dd6a762506260b38a2d3e5b464213c2e47fa3877429fe9ee60e071a31a07d7", false},
}
for _, test := range tests {
pp, err := QueryIdentifier(context.Background(), test.input)
if test.expectError {
assert.Error(t, err, "expected error for input: %s", test.input)
} else {
assert.NoError(t, err, "did not expect error for input: %s", test.input)
assert.Equal(t, test.expectedKey, pp.PublicKey, "for input: %s", test.input)
}
}
}