generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
51 lines (45 loc) · 1.12 KB
/
utils_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
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style license that can be found
// in the LICENSE file.
package dnspodcn
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestFormatDomain(t *testing.T) {
cases := []struct {
domain, expected string
}{
{"example.com", "example.com"},
{"example.com.", "example.com"},
{"abc.example.com", "abc.example.com"},
{"abc.example.com.", "abc.example.com"},
}
for _, test := range cases {
assert.Equal(t, test.expected, formatDomain(test.domain))
}
}
func TestFormatSubdomain(t *testing.T) {
cases := []struct {
domain, subdomain, expected string
}{
{"example.com", "foo.example.com", "foo"},
{"example.com", "bar.example.com.", "bar"},
}
for _, test := range cases {
assert.Equal(t, test.expected, formatSubdomain(test.domain, test.subdomain))
}
}
func TestFormatTTL(t *testing.T) {
cases := []struct {
ttl time.Duration
expected string
}{
{60 * time.Second, "60"},
{time.Hour, "3600"},
}
for _, test := range cases {
assert.Equal(t, test.expected, formatTTL(test.ttl))
}
}