add test
This commit is contained in:
+28
-1
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user