This commit is contained in:
Jay
2019-05-09 16:13:25 +08:00
parent e6f22deb49
commit 4fa99f16bd
11 changed files with 306 additions and 9 deletions
+28 -1
View File
@@ -71,4 +71,31 @@ func LoadConfig(p ...string) error {
func GetConfig() *Config { return conf }
// GetV4Data -
func (p DomainData) GetV4Data() {}
func (p DomainData) GetV4Data() DomainData {
domain := DomainData{}
domain.Name = p.Name
if len(p.Records) == 0 {
return domain
}
for _, it := range p.Records {
if it.Type == "A" {
domain.Records = append(domain.Records, it)
}
}
return domain
}
// GetV6Data -
func (p DomainData) GetV6Data() DomainData {
domain := DomainData{}
domain.Name = p.Name
if len(p.Records) == 0 {
return domain
}
for _, it := range p.Records {
if it.Type == "AAAA" {
domain.Records = append(domain.Records, it)
}
}
return domain
}
+78
View File
@@ -0,0 +1,78 @@
package config
import (
"os"
"path"
"reflect"
"testing"
)
func TestLoadConfig(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
p := path.Join(wd, "../..", "config.default.yml")
err = LoadConfig(p)
if err != nil {
t.Fatal(err)
}
}
func TestGetConfig(t *testing.T) {
conf := GetConfig()
if conf == nil {
t.Fail()
}
}
func TestDomainData_GetV6Data(t *testing.T) {
type fields struct {
Name string
Records []RecordData
}
tests := []struct {
name string
fields fields
want DomainData
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := DomainData{
Name: tt.fields.Name,
Records: tt.fields.Records,
}
if got := p.GetV6Data(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("DomainData.GetV6Data() = %v, want %v", got, tt.want)
}
})
}
}
func TestDomainData_GetV4Data(t *testing.T) {
type fields struct {
Name string
Records []RecordData
}
tests := []struct {
name string
fields fields
want DomainData
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := DomainData{
Name: tt.fields.Name,
Records: tt.fields.Records,
}
if got := p.GetV4Data(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("DomainData.GetV4Data() = %v, want %v", got, tt.want)
}
})
}
}