-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mock DNS package, extend testing (#630)
decided to expand the tests for the DNS package (the current coverage is only 20%). Consequence: - I had to split the creation of ObjectManager and infoblox provider - FakeInfoblox client is no longer needed - we have mocks (cleaner design separates test code from execution code) - I don't need to keep the Overrides.FakeInfoblox switch in the config - I'll remove it in the next PR - We can test more - in the next PR I will extend the DNS package testing - I moved functions `checkZoneDelegated`, `filterOutDelegateTo` from `ib-client.go` to `infoblox-client.go`. IBX provider constructor accepts ObjectManager interface now so I had to extend factory and fix several tests. To test the change, I created one test `TestCreateZoneDelegationForExternalDNS` and generated the necessary mocks. We currently have around 40% coverage but as said, will add new tests in following PR. Signed-off-by: kuritka <[email protected]>
- Loading branch information
Showing
10 changed files
with
311 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,6 +297,8 @@ mocks: | |
go install github.com/golang/mock/[email protected] | ||
mockgen -source=controllers/providers/assistant/assistant.go -destination=controllers/providers/assistant/assistant_mock.go -package=assistant | ||
mockgen -source=controllers/providers/dns/dns.go -destination=controllers/providers/dns/dns_mock.go -package=dns | ||
mockgen -source=controllers/providers/dns/infoblox-client.go -destination=controllers/providers/dns/infoblox-client_mock.go -package=dns | ||
mockgen -destination=controllers/providers/dns/infoblox-connection_mock.go -package=dns github.com/infobloxopen/infoblox-go-client IBConnector | ||
$(call golic) | ||
|
||
# remove clusters and redeploy | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2021 The k8gb Contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic | ||
*/ | ||
package dns | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/AbsaOSS/k8gb/controllers/depresolver" | ||
ibclient "github.com/infobloxopen/infoblox-go-client" | ||
) | ||
|
||
type InfobloxClient interface { | ||
GetObjectManager() (objMgr *ibclient.ObjectManager, err error) | ||
} | ||
|
||
type Client struct { | ||
objMgr *ibclient.ObjectManager | ||
config depresolver.Config | ||
} | ||
|
||
func NewInfobloxClient(config depresolver.Config) *Client { | ||
return &Client{ | ||
config: config, | ||
} | ||
} | ||
|
||
func (c *Client) GetObjectManager() (objMgr *ibclient.ObjectManager, err error) { | ||
hostConfig := ibclient.HostConfig{ | ||
Host: c.config.Infoblox.Host, | ||
Version: c.config.Infoblox.Version, | ||
Port: strconv.Itoa(c.config.Infoblox.Port), | ||
Username: c.config.Infoblox.Username, | ||
Password: c.config.Infoblox.Password, | ||
} | ||
transportConfig := ibclient.NewTransportConfig("false", c.config.Infoblox.HTTPRequestTimeout, c.config.Infoblox.HTTPPoolConnections) | ||
requestBuilder := &ibclient.WapiRequestBuilder{} | ||
requestor := &ibclient.WapiHttpRequestor{} | ||
conn, err := ibclient.NewConnector(hostConfig, transportConfig, requestBuilder, requestor) | ||
if err != nil { | ||
return | ||
} | ||
defer func() { | ||
err = conn.Logout() | ||
}() | ||
c.objMgr = ibclient.NewObjectManager(conn, "k8gbclient", "") | ||
return | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.