Files
EdgeAPI/internal/dnsclients/provider_custom_http_test.go

64 lines
1.2 KiB
Go
Raw Permalink Normal View History

2021-01-28 11:29:57 +08:00
package dnsclients
import (
2024-07-27 14:15:25 +08:00
"testing"
2021-06-02 18:13:48 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
2021-01-28 11:29:57 +08:00
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
)
func TestCustomHTTPProvider_GetDomains(t *testing.T) {
provider := CustomHTTPProvider{}
err := provider.Auth(maps.Map{
"url": "http://127.0.0.1:2345/dns",
"secret": "123456",
})
if err != nil {
t.Fatal(err)
}
domains, err := provider.GetDomains()
if err != nil {
t.Fatal(err)
}
t.Log(domains)
}
2021-01-28 11:29:57 +08:00
func TestCustomHTTPProvider_AddRecord(t *testing.T) {
provider := CustomHTTPProvider{}
err := provider.Auth(maps.Map{
"url": "http://127.0.0.1:1234/dns",
"secret": "123456",
})
if err != nil {
t.Fatal(err)
}
2021-06-02 18:13:48 +08:00
err = provider.AddRecord("hello.com", &dnstypes.Record{
2021-01-28 11:29:57 +08:00
Id: "",
Name: "world",
2021-06-02 18:13:48 +08:00
Type: dnstypes.RecordTypeA,
2021-01-28 11:29:57 +08:00
Value: "127.0.0.1",
Route: "default",
})
if err != nil {
t.Fatal(err)
}
t.Log("ok")
}
func TestCustomHTTPProvider_GetRecords(t *testing.T) {
provider := CustomHTTPProvider{}
err := provider.Auth(maps.Map{
"url": "http://127.0.0.1:1234/dns",
"secret": "123456",
})
if err != nil {
t.Fatal(err)
}
records, err := provider.GetRecords("hello.com")
if err != nil {
t.Fatal(err)
}
logs.PrintAsJSON(records, t)
}