mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-10-27 00:31:09 +01:00
FIX: Make test working
This commit is contained in:
parent
6d1d133ee7
commit
787fdd08bb
@ -23,6 +23,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ovh/go-ovh/ovh"
|
"github.com/ovh/go-ovh/ovh"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"sigs.k8s.io/external-dns/endpoint"
|
"sigs.k8s.io/external-dns/endpoint"
|
||||||
@ -31,6 +32,13 @@ import (
|
|||||||
|
|
||||||
type mockGoDaddyClient struct {
|
type mockGoDaddyClient struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
|
currentTest *testing.T
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMockGoDaddyClient(t *testing.T) *mockGoDaddyClient {
|
||||||
|
return &mockGoDaddyClient{
|
||||||
|
currentTest: t,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -39,6 +47,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *mockGoDaddyClient) Post(endpoint string, input interface{}, output interface{}) error {
|
func (c *mockGoDaddyClient) Post(endpoint string, input interface{}, output interface{}) error {
|
||||||
|
log.Infof("POST: %s - %v", endpoint, input)
|
||||||
stub := c.Called(endpoint, input)
|
stub := c.Called(endpoint, input)
|
||||||
data, _ := json.Marshal(stub.Get(0))
|
data, _ := json.Marshal(stub.Get(0))
|
||||||
json.Unmarshal(data, output)
|
json.Unmarshal(data, output)
|
||||||
@ -46,6 +55,7 @@ func (c *mockGoDaddyClient) Post(endpoint string, input interface{}, output inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockGoDaddyClient) Patch(endpoint string, input interface{}, output interface{}) error {
|
func (c *mockGoDaddyClient) Patch(endpoint string, input interface{}, output interface{}) error {
|
||||||
|
log.Infof("PATCH: %s - %v", endpoint, input)
|
||||||
stub := c.Called(endpoint, input)
|
stub := c.Called(endpoint, input)
|
||||||
data, _ := json.Marshal(stub.Get(0))
|
data, _ := json.Marshal(stub.Get(0))
|
||||||
json.Unmarshal(data, output)
|
json.Unmarshal(data, output)
|
||||||
@ -53,6 +63,7 @@ func (c *mockGoDaddyClient) Patch(endpoint string, input interface{}, output int
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockGoDaddyClient) Put(endpoint string, input interface{}, output interface{}) error {
|
func (c *mockGoDaddyClient) Put(endpoint string, input interface{}, output interface{}) error {
|
||||||
|
log.Infof("PUT: %s - %v", endpoint, input)
|
||||||
stub := c.Called(endpoint, input)
|
stub := c.Called(endpoint, input)
|
||||||
data, _ := json.Marshal(stub.Get(0))
|
data, _ := json.Marshal(stub.Get(0))
|
||||||
json.Unmarshal(data, output)
|
json.Unmarshal(data, output)
|
||||||
@ -60,6 +71,7 @@ func (c *mockGoDaddyClient) Put(endpoint string, input interface{}, output inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockGoDaddyClient) Get(endpoint string, output interface{}) error {
|
func (c *mockGoDaddyClient) Get(endpoint string, output interface{}) error {
|
||||||
|
log.Infof("GET: %s", endpoint)
|
||||||
stub := c.Called(endpoint)
|
stub := c.Called(endpoint)
|
||||||
data, _ := json.Marshal(stub.Get(0))
|
data, _ := json.Marshal(stub.Get(0))
|
||||||
json.Unmarshal(data, output)
|
json.Unmarshal(data, output)
|
||||||
@ -67,6 +79,7 @@ func (c *mockGoDaddyClient) Get(endpoint string, output interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockGoDaddyClient) Delete(endpoint string, output interface{}) error {
|
func (c *mockGoDaddyClient) Delete(endpoint string, output interface{}) error {
|
||||||
|
log.Infof("DELETE: %s", endpoint)
|
||||||
stub := c.Called(endpoint)
|
stub := c.Called(endpoint)
|
||||||
data, _ := json.Marshal(stub.Get(0))
|
data, _ := json.Marshal(stub.Get(0))
|
||||||
json.Unmarshal(data, output)
|
json.Unmarshal(data, output)
|
||||||
@ -75,7 +88,7 @@ func (c *mockGoDaddyClient) Delete(endpoint string, output interface{}) error {
|
|||||||
|
|
||||||
func TestGoDaddyZones(t *testing.T) {
|
func TestGoDaddyZones(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
client := new(mockGoDaddyClient)
|
client := newMockGoDaddyClient(t)
|
||||||
provider := &GDProvider{
|
provider := &GDProvider{
|
||||||
client: client,
|
client: client,
|
||||||
domainFilter: endpoint.NewDomainFilter([]string{"com"}),
|
domainFilter: endpoint.NewDomainFilter([]string{"com"}),
|
||||||
@ -109,7 +122,7 @@ func TestGoDaddyZones(t *testing.T) {
|
|||||||
|
|
||||||
func TestGoDaddyZoneRecords(t *testing.T) {
|
func TestGoDaddyZoneRecords(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
client := new(mockGoDaddyClient)
|
client := newMockGoDaddyClient(t)
|
||||||
provider := &GDProvider{
|
provider := &GDProvider{
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
@ -215,7 +228,7 @@ func TestGoDaddyZoneRecords(t *testing.T) {
|
|||||||
|
|
||||||
func TestGoDaddyRecords(t *testing.T) {
|
func TestGoDaddyRecords(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
client := new(mockGoDaddyClient)
|
client := newMockGoDaddyClient(t)
|
||||||
provider := &GDProvider{
|
provider := &GDProvider{
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
@ -359,7 +372,7 @@ func TestGoDaddyNewChange(t *testing.T) {
|
|||||||
gdRecord: gdRecord{
|
gdRecord: gdRecord{
|
||||||
zone: &zoneNameExampleNet,
|
zone: &zoneNameExampleNet,
|
||||||
gdRecordField: gdRecordField{
|
gdRecordField: gdRecordField{
|
||||||
Name: "",
|
Name: "@",
|
||||||
Type: "A",
|
Type: "A",
|
||||||
TTL: 10,
|
TTL: 10,
|
||||||
Data: "203.0.113.42",
|
Data: "203.0.113.42",
|
||||||
@ -435,7 +448,7 @@ func TestGoDaddyNewChange(t *testing.T) {
|
|||||||
|
|
||||||
func TestGoDaddyApplyChanges(t *testing.T) {
|
func TestGoDaddyApplyChanges(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
client := new(mockGoDaddyClient)
|
client := newMockGoDaddyClient(t)
|
||||||
|
|
||||||
provider := &GDProvider{
|
provider := &GDProvider{
|
||||||
client: client,
|
client: client,
|
||||||
@ -462,7 +475,6 @@ func TestGoDaddyApplyChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
client.On("Get", "/v1/domains?statuses=ACTIVE").Return([]gdZone{
|
client.On("Get", "/v1/domains?statuses=ACTIVE").Return([]gdZone{
|
||||||
{
|
{
|
||||||
Domain: zoneNameExampleNet,
|
Domain: zoneNameExampleNet,
|
||||||
@ -481,18 +493,6 @@ func TestGoDaddyApplyChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, nil).Once()
|
}, nil).Once()
|
||||||
|
|
||||||
client.On("Get", "/v1/domains/example.net/records/A/goddady").Return([]gdRecord{
|
|
||||||
{
|
|
||||||
zone: &zoneNameExampleNet,
|
|
||||||
gdRecordField: gdRecordField{
|
|
||||||
Name: "godaddy",
|
|
||||||
Type: "A",
|
|
||||||
TTL: 10,
|
|
||||||
Data: "203.0.113.43",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil).Once()
|
|
||||||
|
|
||||||
client.On("Patch", "/v1/domains/example.net/records", []gdRecordField{
|
client.On("Patch", "/v1/domains/example.net/records", []gdRecordField{
|
||||||
{
|
{
|
||||||
Name: "@",
|
Name: "@",
|
||||||
@ -502,7 +502,7 @@ func TestGoDaddyApplyChanges(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}).Return(nil, nil).Once()
|
}).Return(nil, nil).Once()
|
||||||
|
|
||||||
client.On("Delete", "/v1/domains/example.net/records/A/@").Return(nil, nil).Once()
|
client.On("Delete", "/v1/domains/example.net/records/A/godaddy").Return(nil, nil).Once()
|
||||||
|
|
||||||
// Basic changes
|
// Basic changes
|
||||||
assert.NoError(provider.ApplyChanges(context.TODO(), &changes))
|
assert.NoError(provider.ApplyChanges(context.TODO(), &changes))
|
||||||
@ -523,9 +523,9 @@ func TestGoDaddyApplyChanges(t *testing.T) {
|
|||||||
|
|
||||||
client.On("Get", "/v1/domains/example.net/records").Return([]gdRecord{}, nil).Once()
|
client.On("Get", "/v1/domains/example.net/records").Return([]gdRecord{}, nil).Once()
|
||||||
|
|
||||||
client.On("Patch", "/v1/domains/example.net/records/A/godaddy", []gdRecordField{
|
client.On("Patch", "/v1/domains/example.net/records", []gdRecordField{
|
||||||
{
|
{
|
||||||
Name: "",
|
Name: "@",
|
||||||
Type: "A",
|
Type: "A",
|
||||||
TTL: 10,
|
TTL: 10,
|
||||||
Data: "203.0.113.42",
|
Data: "203.0.113.42",
|
||||||
@ -550,7 +550,7 @@ func TestGoDaddyApplyChanges(t *testing.T) {
|
|||||||
|
|
||||||
func TestGoDaddyChange(t *testing.T) {
|
func TestGoDaddyChange(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
client := new(mockGoDaddyClient)
|
client := newMockGoDaddyClient(t)
|
||||||
provider := &GDProvider{
|
provider := &GDProvider{
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user