Skip to content

Commit

Permalink
align tests w/ infoblox-client@v2
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <[email protected]>
  • Loading branch information
jkremser committed Aug 3, 2022
1 parent bcbc8fa commit 0be653c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
12 changes: 10 additions & 2 deletions controllers/providers/dns/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
*/

import (
"errors"
"fmt"
"reflect"
"time"
Expand All @@ -40,6 +41,8 @@ type InfobloxProvider struct {

var m = metrics.Metrics()

const infobloxView = "default"

func NewInfobloxDNS(config depresolver.Config, assistant assistant.Assistant, client InfobloxClient) *InfobloxProvider {
return &InfobloxProvider{
client: client,
Expand Down Expand Up @@ -292,14 +295,19 @@ func (p *InfobloxProvider) deleteZoneDelegated(o ibcl.IBObjectManager, fqdn stri

func (p *InfobloxProvider) createTXTRecord(o ibcl.IBObjectManager, name string, text string, ttl uint32) (res *ibcl.RecordTXT, err error) {
start := time.Now()
res, err = o.CreateTXTRecord("", name, text, ttl, true, "default", nil)
res, err = o.CreateTXTRecord(infobloxView, name, text, ttl, true, "default", nil)
m.InfobloxObserveRequestDuration(start, metrics.CreateTXTRecord, err == nil)
return
}

func (p *InfobloxProvider) getTXTRecord(o ibcl.IBObjectManager, name string) (res *ibcl.RecordTXT, err error) {
start := time.Now()
res, err = o.GetTXTRecord("", name)
res, err = o.GetTXTRecord(infobloxView, name)
e := &ibcl.NotFoundError{}
if errors.As(err, &e) {
// infoblox-client@v1 wasn't returning the error in case the record was not found, so preserving the contract from v1 here
err = nil
}
m.InfobloxObserveRequestDuration(start, metrics.GetTXTRecord, err == nil)
return
}
Expand Down
22 changes: 9 additions & 13 deletions controllers/providers/dns/infoblox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestInfobloxCreateZoneDelegationForExternalDNS(t *testing.T) {
a.EXPECT().GslbIngressExposedIPs(gomock.Any()).Return(ipRange, nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
con.EXPECT().UpdateObject(gomock.Any(), gomock.Any()).Return(ref, nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
config := defaultConfig
provider := NewInfobloxDNS(config, a, cl)
Expand All @@ -194,12 +194,10 @@ func TestInfobloxCreateZoneDelegationForExternalDNSWithSplitBrainEnabled(t *test
}).Return(nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
con.EXPECT().UpdateObject(gomock.Any(), gomock.Any()).Return(ref, nil).Times(2)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{{Ref: ref}}).
Return(nil).Do(func(arg0 *ibclient.RecordTXT, arg1, arg2 interface{}) {
require.Equal(t, "test-gslb-heartbeat-us-west-1.example.com", arg0.Name)
}).AnyTimes()
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.RecordTXT{{Ref: ref}}).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, &ibclient.RecordTXT{Ref: ref}).AnyTimes()
config := defaultConfig
config.SplitBrainCheck = true
provider := NewInfobloxDNS(config, a, cl)
Expand All @@ -221,9 +219,10 @@ func TestInfobloxCreateZoneDelegationForExternalDNSWithSplitBrainEnabledCreating
a.EXPECT().InspectTXTThreshold(gomock.Any(), gomock.Any()).Return(nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
con.EXPECT().UpdateObject(gomock.Any(), gomock.Any()).Return(ref, nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{}).Return(nil).AnyTimes()
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.RecordTXT{}).Return(nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, &ibclient.RecordTXT{}).Return(nil).Times(1)
config := defaultConfig
config.SplitBrainCheck = true
provider := NewInfobloxDNS(config, a, cl)
Expand All @@ -244,12 +243,9 @@ func TestInfobloxFinalize(t *testing.T) {
con.EXPECT().DeleteObject(gomock.Any()).Return(ref, nil).Do(func(arg0 string) {
require.Equal(t, arg0, ref)
}).AnyTimes()
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.ZoneDelegated{defaultDelegatedZone}).
Return(nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{{Ref: ref}}).
Return(nil).Do(func(arg0 *ibclient.RecordTXT, arg1, arg2 interface{}) {
require.Equal(t, "test-gslb-heartbeat-us-west-1.example.com", arg0.Name)
}).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(3, []ibclient.RecordTXT{{Ref: ref}}).Times(1)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
config := defaultConfig
provider := NewInfobloxDNS(config, a, cl)
Expand Down

0 comments on commit 0be653c

Please sign in to comment.