-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser_ua_test.go
103 lines (89 loc) · 4.58 KB
/
parser_ua_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
package whoisparser
import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
func TestParserUa(t *testing.T) {
assertParamsMap := AssertParamsMap{
"Registrar": {
{TargetField: "DomainName", ExpectedResult: "viyar.ua", AssertType: AssertTypeEqual},
{TargetField: "NameServers", ExpectedResult: "ns10.uadns.com", AssertType: AssertTypeContains},
{TargetField: "DomainStatus", ExpectedResult: "ok", AssertType: AssertTypeEqual},
{TargetField: "CreatedDate", ExpectedResult: "2013-08-09 13:13:06+03", AssertType: AssertTypeEqual},
{TargetField: "UpdatedDate", ExpectedResult: "2019-07-10 12:54:59+03", AssertType: AssertTypeEqual},
{TargetField: "ExpirationDate", ExpectedResult: "2020-08-09 13:13:06+03", AssertType: AssertTypeEqual},
{TargetField: "Emails", ExpectedResult: "abuse@nic.ua", AssertType: AssertTypeEqual},
{TargetField: "RegistrarName", ExpectedResult: "ua.nic", AssertType: AssertTypeEqual},
},
"Tech": {
{TargetField: "Name", ExpectedResult: "NIC.UA LLC", AssertType: AssertTypeEqual},
{TargetField: "Organization", ExpectedResult: "ТОВ \"НІК.ЮЕЙ\"", AssertType: AssertTypeEqual},
{TargetField: "Street", ExpectedResult: "Plehanova", AssertType: AssertTypeEqual},
{TargetField: "City", ExpectedResult: "DNIPRO", AssertType: AssertTypeEqual},
{TargetField: "PostalCode", ExpectedResult: "04050", AssertType: AssertTypeEqual},
{TargetField: "Country", ExpectedResult: "UA", AssertType: AssertTypeEqual},
{TargetField: "Phone", ExpectedResult: "+380.445933222", AssertType: AssertTypeEqual},
{TargetField: "Fax", ExpectedResult: "+380.445937569", AssertType: AssertTypeEqual},
{TargetField: "Email", ExpectedResult: "support@nic.ua", AssertType: AssertTypeEqual},
},
"Admin": {
{TargetField: "Name", ExpectedResult: "Test1", AssertType: AssertTypeEqual},
{TargetField: "Organization", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Street", ExpectedResult: "not published", AssertType: AssertTypeEqual},
{TargetField: "City", ExpectedResult: "not published", AssertType: AssertTypeEqual},
{TargetField: "PostalCode", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Country", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Phone", ExpectedResult: "test41234", AssertType: AssertTypeEqual},
{TargetField: "Fax", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Email", ExpectedResult: "test2@email.test", AssertType: AssertTypeEqual},
},
"Registrant": {
{TargetField: "Name", ExpectedResult: "RegTEst1", AssertType: AssertTypeEqual},
{TargetField: "Organization", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Street", ExpectedResult: "Address1TEst", AssertType: AssertTypeEqual},
{TargetField: "City", ExpectedResult: "Address2Test", AssertType: AssertTypeEqual},
{TargetField: "PostalCode", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Country", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Phone", ExpectedResult: "Phoen1TEst", AssertType: AssertTypeEqual},
{TargetField: "Fax", ExpectedResult: "", AssertType: AssertTypeEqual},
{TargetField: "Email", ExpectedResult: "REgEmainLTEst", AssertType: AssertTypeEqual},
},
}
testDataFilepath := "test_data/whois_ua/viyar.ua.txt"
parserName := ".ua parser"
runParserAssertions(t, uaParser, parserName, testDataFilepath, assertParamsMap)
}
func TestParserUaNoSuchDomainErr(t *testing.T) {
var fileBytes []byte
var err error
var text string
var whoisRecord *Record
fileBytes, err = ioutil.ReadFile("test_data/whois_ua/no_such_domain.txt")
assert.NoError(t, err, "failed to open file with test data")
text = string(fileBytes)
whoisRecord = uaParser.Parse(text)
assert.True(t, whoisRecord.ErrCode == ErrCodeNoSuchDomain)
assert.Nil(t, whoisRecord.Registrar)
assert.Nil(t, whoisRecord.Registrant)
assert.Nil(t, whoisRecord.Bill)
assert.Nil(t, whoisRecord.Admin)
assert.Nil(t, whoisRecord.Tech)
}
func TestParserUaMalformedRequest(t *testing.T) {
var fileBytes []byte
var err error
var text string
var whoisRecord *Record
fileBytes, err = ioutil.ReadFile("test_data/whois_ua/malformed_request.txt")
assert.NoError(t, err, "failed to open file with test data")
text = string(fileBytes)
whoisRecord = uaParser.Parse(text)
assert.NoError(t, err, "failed to open file with test data")
assert.Equal(t, ErrCodeMalformedRequest, whoisRecord.ErrCode)
assert.Nil(t, whoisRecord.Registrar)
assert.Nil(t, whoisRecord.Registrant)
assert.Nil(t, whoisRecord.Bill)
assert.Nil(t, whoisRecord.Admin)
assert.Nil(t, whoisRecord.Tech)
}