Skip to content

Commit

Permalink
test(api): update the test of api
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Aug 5, 2021
1 parent a507411 commit cac8e25
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ A small and fast DDNS updater for Cloudflare.
🔸 Effective GID: 1000
🔸 Supplementary GIDs: (empty)
🔇 Quiet mode enabled.
🐣 Added a new A record of …… (ID: ……).
🐣 Added a new AAAA record of …… (ID: ……).
🐣 Added a new A record of "……" (ID: ……).
🐣 Added a new AAAA record of "……" (ID: ……).
```

## 📜 Highlights
Expand Down
95 changes: 70 additions & 25 deletions internal/api/fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,62 @@ import (
"github.com/favonia/cloudflare-ddns/internal/api"
)

func TestFQDNString(t *testing.T) {
func TestFQDNToASCII(t *testing.T) {
t.Parallel()

require.NoError(t, quick.Check(
func(s string) bool {
return api.FQDN(s).String() == s
return api.FQDN(s).ToASCII() == s
},
nil,
))
}

func TestFQDNDescribe(t *testing.T) {
t.Parallel()
for _, tc := range [...]struct {
input string
expected string
ok bool
errString string
}{
// The following examples were adapted from https://unicode.org/cldr/utility/idna.jsp
{"fass.de", "fass.de", true, ""},
{"xn--fa-hia.de", "faß.de", true, ""},
{"xn--f-qfao.de", "fäß.de", true, ""},
{"xn--fa-hia.de", "faß.de", true, ""},
{"xn--yzg.com", "₹.com", true, ""},
{"xn--n00d.com", "𑀓.com", true, ""},
{"xn--a.com", "xn--a.com", false, "idna: disallowed rune U+0080"},
{"xn--a.com", "xn--a.com", false, "idna: invalid label \"\\u0080\""},
{"xn--ab-j1t", "xn--ab-j1t", false, "idna: invalid label \"a\\u200cb\""},
{"xn--ab-j1t", "xn--ab-j1t", false, "idna: invalid label \"a\\u200cb\""},
{"xn--bb-eka.at", "öbb.at", true, ""},
{"xn--og-09a.de", "ȡog.de", true, ""},
{"xn--53h.de", "☕.de", true, ""},
{"xn--iny-zx5a.de", "i♥ny.de", true, ""},
{"xn--abc-rs4b422ycvb.co.jp", "abc・日本.co.jp", true, ""},
{"xn--wgv71a.co.jp", "日本.co.jp", true, ""},
{"xn--co-wuw5954azlb.jp", "xn--co-wuw5954azlb.jp", false, "idna: disallowed rune U+2488"},
{"xn--x-xbb7i.de", "x̧́.de", true, ""},
{"xn--wxaijb9b.gr", "σόλος.gr", true, ""},
{"xn--wxaikc6b.xn--gr-gtd9a1b0g.de", "xn--wxaikc6b.xn--gr-gtd9a1b0g.de", false, "idna: invalid label \"σόλοσ.grعربي.de\""},
{"xn--ngbrx4e.de", "عربي.de", true, ""},
{"xn--mgba3gch31f.de", "نامهای.de", true, ""},
{"xn--mgba3gch31f060k.de", "نامه\u200cای.de", true, ""},
// some other test cases
{"xn--a.xn--a.xn--a.com", "xn--a.xn--a.xn--a.com", false, "idna: invalid label \"\\u0080\""},
{"a.com....", "a.com....", true, ""},
{"a.com", "a.com", true, ""},
} {
tc := tc
t.Run(tc.input, func(t *testing.T) {
t.Parallel()
require.Equal(t, tc.expected, api.FQDN(tc.input).Describe())
})
}
}

func TestNewFQDN(t *testing.T) {
t.Parallel()
for _, tc := range [...]struct {
Expand All @@ -30,40 +75,40 @@ func TestNewFQDN(t *testing.T) {
ok bool
errString string
}{
// The following examples were reproduced from https://unicode.org/cldr/utility/idna.jsp
// The following examples were adapted from https://unicode.org/cldr/utility/idna.jsp
{"fass.de", "fass.de", true, ""},
{"faß.de", "faß.de", true, ""},
{"fäß.de", "fäß.de", true, ""},
{"xn--fa-hia.de", "faß.de", true, ""},
{"₹.com", ".com", true, ""},
{"𑀓.com", "𑀓.com", true, ""},
{"faß.de", "xn--fa-hia.de", true, ""},
{"fäß.de", "xn--f-qfao.de", true, ""},
{"xn--fa-hia.de", "xn--fa-hia.de", true, ""},
{"₹.com", "xn--yzg.com", true, ""},
{"𑀓.com", "xn--n00d.com", true, ""},
{"\u0080.com", "xn--a.com", false, "idna: disallowed rune U+0080"},
{"xn--a.com", "xn--a.com", false, "idna: invalid label \"\\u0080\""},
{"a\u200Cb", "xn--ab-j1t", false, "idna: invalid label \"a\\u200cb\""},
{"xn--ab-j1t", "xn--ab-j1t", false, "idna: invalid label \"a\\u200cb\""},
{"öbb.at", "öbb.at", true, ""},
{"ÖBB.at", "öbb.at", true, ""},
{"ÖBB.at", "öbb.at", true, ""},
{"ȡog.de", "ȡog.de", true, ""},
{"☕.de", "☕.de", true, ""},
{"I♥NY.de", "i♥ny.de", true, ""},
{"ABC・日本.co.jp", "abc・日本.co.jp", true, ""},
{"日本。co。jp", "日本.co.jp", true, ""},
{"日本。co.jp", "日本.co.jp", true, ""},
{"\u00F6bb.at", "xn--bb-eka.at", true, ""},
{"o\u0308bb.at", "xn--bb-eka.at", true, ""},
{"\u00D6BB.at", "xn--bb-eka.at", true, ""},
{"O\u0308BB.at", "xn--bb-eka.at", true, ""},
{"ȡog.de", "xn--og-09a.de", true, ""},
{"☕.de", "xn--53h.de", true, ""},
{"I♥NY.de", "xn--iny-zx5a.de", true, ""},
{"ABC・日本.co.jp", "xn--abc-rs4b422ycvb.co.jp", true, ""},
{"日本。co。jp", "xn--wgv71a.co.jp", true, ""},
{"日本。co.jp", "xn--wgv71a.co.jp", true, ""},
{"日本⒈co.jp", "xn--co-wuw5954azlb.jp", false, "idna: disallowed rune U+2488"},
{"x\u0327\u0301.de", "x̧́.de", true, ""},
{"x\u0301\u0327.de", "x̧́.de", true, ""},
{"σόλος.gr", "σόλος.gr", true, ""},
{"Σόλος.gr", "σόλος.gr", true, ""},
{"x\u0327\u0301.de", "xn--x-xbb7i.de", true, ""},
{"x\u0301\u0327.de", "xn--x-xbb7i.de", true, ""},
{"σόλος.gr", "xn--wxaijb9b.gr", true, ""},
{"Σόλος.gr", "xn--wxaijb9b.gr", true, ""},
{"ΣΌΛΟΣ.grﻋﺮﺑﻲ.de", "xn--wxaikc6b.xn--gr-gtd9a1b0g.de", false, "idna: invalid label \"σόλοσ.grعربي.de\""},
{"عربي.de", "عربي.de", true, ""},
{"نامهای.de", "نامهای.de", true, ""},
{"نامه\u200Cای.de", "نامه\u200cای.de", true, ""},
{"عربي.de", "xn--ngbrx4e.de", true, ""},
{"نامهای.de", "xn--mgba3gch31f.de", true, ""},
{"نامه\u200Cای.de", "xn--mgba3gch31f060k.de", true, ""},
// some other test cases
{"xn--a.xn--a.xn--a.com", "xn--a.xn--a.xn--a.com", false, "idna: invalid label \"\\u0080\""},
{"a.com...。", "a.com...", true, ""},
{"..。..a.com", "a.com", true, ""},
{"O\u0308", "\u00F6", true, ""},
} {
tc := tc
t.Run(tc.input, func(t *testing.T) {
Expand Down

0 comments on commit cac8e25

Please sign in to comment.