Documentation ¶
Overview ¶
Package mockns1 provides utilities to run a mock service that emulates the NS1 API suitible for mock testing code that relies on the gopkg.in/ns1/ns1-go.v2 pacakge
Example ¶
package main import ( "net/http" "net/url" "testing" "github.com/stretchr/testify/require" "gopkg.in/ns1/ns1-go.v2/mockns1" api "gopkg.in/ns1/ns1-go.v2/rest" "gopkg.in/ns1/ns1-go.v2/rest/model/dns" ) func main() { t := new(testing.T) // Setup the mock service mock, doer, err := mockns1.New(t) require.Nil(t, err) defer mock.Shutdown() // Create your NS1 client and configure it for the mock service ns1 := api.NewClient(doer, api.SetAPIKey("apikey")) ns1.Endpoint, _ = url.Parse("https://" + mock.Address + "/v1/") // Add your test case (zone list in this example) require.Nil(t, mock.AddTestCase(http.MethodGet, "zones", http.StatusOK, nil, nil, "", []*dns.Zone{{Zone: "foo.bar"}})) // Perform your tests zones, _, err := ns1.Zones.List() require.Nil(t, err) require.Equal(t, 1, len(zones)) require.Equal(t, "foo.bar", zones[0].Zone) }
Output:
Index ¶
- type Service
- func (s *Service) AddActivateVersionTestCase(zoneName string, versionID int64, requestHeaders, responseHeaders http.Header) error
- func (s *Service) AddApplicationCreateTestCase(requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddApplicationDeleteTestCase(id string, requestHeaders, responseHeaders http.Header) error
- func (s *Service) AddApplicationGetTestCase(id string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddApplicationTestCase(requestHeaders, responseHeaders http.Header, response []*pulsar.Application) error
- func (s *Service) AddApplicationUpdateTestCase(requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddCreateVersionTestCase(zoneName string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddDNSViewCreateTestCase(requestHeaders, responseHeaders http.Header, dnsView, response *dns.View) error
- func (s *Service) AddDNSViewGetPreferencesTestCase(requestHeaders, responseHeaders http.Header, response interface{}) error
- func (s *Service) AddDNSViewGetTestCase(viewName string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddDNSViewListTestCase(requestHeaders, responseHeaders http.Header, response []*dns.View) error
- func (s *Service) AddDNSViewUpdatePreferencesTestCase(requestHeaders, responseHeaders http.Header, body, response interface{}) error
- func (s *Service) AddDNSViewUpdateTestCase(requestHeaders, responseHeaders http.Header, dnsView, response *dns.View) error
- func (s *Service) AddDatasetCreateTestCase(requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddDatasetDeleteTestCase(id string, requestHeaders, responseHeaders http.Header) error
- func (s *Service) AddDatasetGetReportTestCase(id string, reportId string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddDatasetGetTestCase(id string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddDatasetListTestCase(requestHeaders, responseHeaders http.Header, response []*dataset.Dataset) error
- func (s *Service) AddDeleteVersionTestCase(zoneName string, versionID int64, requestHeaders, responseHeaders http.Header) error
- func (s *Service) AddGlobalIPWhitelistCreateTestCase(requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddGlobalIPWhitelistDeleteTestCase(whitelistID string, requestHeaders, responseHeaders http.Header) error
- func (s *Service) AddGlobalIPWhitelistGetTestCase(whitelistID string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddGlobalIPWhitelistListTestCase(requestHeaders, responseHeaders http.Header, response []*account.IPWhitelist) error
- func (s *Service) AddGlobalIPWhitelistUpdateTestCase(requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddPulsarJobCreateTestCase(requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.Job) error
- func (s *Service) AddPulsarJobDeleteTestCase(requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.Job) error
- func (s *Service) AddPulsarJobGetTestCase(appid, jobid string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddPulsarJobListTestCase(appid string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddPulsarJobUpdateTestCase(requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.Job) error
- func (s *Service) AddTestCase(method, uri string, returnStatus int, ...) error
- func (s *Service) AddTsigKeyCreateTestCase(requestHeaders, responseHeaders http.Header, tsigKey, response *dns.TSIGKey) error
- func (s *Service) AddTsigKeyDeleteTestCase(requestHeaders, responseHeaders http.Header, tsigKey, response *dns.TSIGKey) error
- func (s *Service) AddTsigKeyGetTestCase(name string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddTsigKeyListTestCase(requestHeaders, responseHeaders http.Header, response []*dns.TSIGKey) error
- func (s *Service) AddTsigKeyUpdateTestCase(requestHeaders, responseHeaders http.Header, tsigKey, response *dns.TSIGKey) error
- func (s *Service) AddVersionListTestCase(zoneName string, requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddZoneCreateTestCase(requestHeaders, responseHeaders http.Header, zone, response *dns.Zone) error
- func (s *Service) AddZoneDeleteTestCase(name string, requestHeaders, responseHeaders http.Header) error
- func (s *Service) AddZoneGetTestCase(name string, requestHeaders, responseHeaders http.Header, response *dns.Zone, ...) error
- func (s *Service) AddZoneListTestCase(requestHeaders, responseHeaders http.Header, response []*dns.Zone) error
- func (s *Service) AddZoneUpdateTestCase(requestHeaders, responseHeaders http.Header, zone, response *dns.Zone) error
- func (s *Service) ClearTestCases()
- func (s *Service) NetworkGetTestCase(requestHeaders, responseHeaders http.Header, response []*dns.Network) error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) Shutdown()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct { // Address is set by New() to the listen address of the mock server Address string // contains filtered or unexported fields }
Service is a controller for a mock server suitable for responding to gopkg.in/ns1/ns1-go.v2 client requests. This object should always be initialized via the New() function.
func New ¶
New creates and starts a new TLS based *httptest.Server instance. As a self signed certificate is being used by the server, your HTTP client being used with your NS1 client needs to disable TLS verification. The returned Doer is a *http.Client with TLS verification disable that is appropriate for use.
The mock service is compatible with both testing.B and testing.T instances so that it may be used in benchmarking as well as testing. If a testing.B instance is supplied the timer will be stopped for the duration of the ServeHTTP() and AddTestCase() methods to minimise the impact on your benchmark statistics.
func (*Service) AddActivateVersionTestCase ¶ added in v2.7.7
func (s *Service) AddActivateVersionTestCase( zoneName string, versionID int64, requestHeaders, responseHeaders http.Header, ) error
AddActivateVersionTestCase sets up a test case for the api.Client.Versions.Activate() function
func (*Service) AddApplicationCreateTestCase ¶
func (s *Service) AddApplicationCreateTestCase( requestHeaders, responseHeaders http.Header, application, response *pulsar.Application, ) error
AddApplicationCreateTestCase sets up a test case for the api.Client.application.Create() function
func (*Service) AddApplicationDeleteTestCase ¶
func (s *Service) AddApplicationDeleteTestCase( id string, requestHeaders, responseHeaders http.Header, ) error
AddApplicationDeleteTestCase sets up a test case for the api.Client.application.Delete() function
func (*Service) AddApplicationGetTestCase ¶
func (s *Service) AddApplicationGetTestCase( id string, requestHeaders, responseHeaders http.Header, response *pulsar.Application, ) error
AddApplicationGetTestCase sets up a test case for the api.Client.application.Get() function
func (*Service) AddApplicationTestCase ¶
func (s *Service) AddApplicationTestCase( requestHeaders, responseHeaders http.Header, response []*pulsar.Application, ) error
AddApplicationTestCase sets up a test case for the api.Client.application.List() function
func (*Service) AddApplicationUpdateTestCase ¶
func (s *Service) AddApplicationUpdateTestCase( requestHeaders, responseHeaders http.Header, application, response *pulsar.Application, ) error
AddApplicationUpdateTestCase sets up a test case for the api.Client.application.Update() function
func (*Service) AddCreateVersionTestCase ¶ added in v2.7.7
func (s *Service) AddCreateVersionTestCase( zoneName string, requestHeaders, responseHeaders http.Header, response *dns.Version, ) error
AddCreateVersionTestCase sets up a test case for the api.Client.Versions.Create() function
func (*Service) AddDNSViewCreateTestCase ¶
func (s *Service) AddDNSViewCreateTestCase( requestHeaders, responseHeaders http.Header, dnsView, response *dns.View, ) error
AddDNSViewCreateTestCase sets up a test case for the api.Client.View.Create() function
func (*Service) AddDNSViewGetPreferencesTestCase ¶
func (s *Service) AddDNSViewGetPreferencesTestCase( requestHeaders, responseHeaders http.Header, response interface{}, ) error
AddDNSViewGetPreferencesTestCase sets up a test case for the api.Client.View.GetPreferences() function
func (*Service) AddDNSViewGetTestCase ¶
func (s *Service) AddDNSViewGetTestCase( viewName string, requestHeaders, responseHeaders http.Header, response *dns.View, ) error
AddDNSViewGetTestCase sets up a test case for the api.Client.View.Get() function
func (*Service) AddDNSViewListTestCase ¶
func (s *Service) AddDNSViewListTestCase( requestHeaders, responseHeaders http.Header, response []*dns.View, ) error
AddDNSViewListTestCase sets up a test case for the api.Client.View.List() function
func (*Service) AddDNSViewUpdatePreferencesTestCase ¶
func (s *Service) AddDNSViewUpdatePreferencesTestCase( requestHeaders, responseHeaders http.Header, body, response interface{}, ) error
AddDNSViewUpdatePreferencesTestCase sets up a test case for the api.Client.View.GetPreferences() function
func (*Service) AddDNSViewUpdateTestCase ¶
func (s *Service) AddDNSViewUpdateTestCase( requestHeaders, responseHeaders http.Header, dnsView, response *dns.View, ) error
AddDNSViewUpdateTestCase sets up a test case for the api.Client.View.Update() function
func (*Service) AddDatasetCreateTestCase ¶ added in v2.8.0
func (s *Service) AddDatasetCreateTestCase( requestHeaders, responseHeaders http.Header, request, response *dataset.Dataset, ) error
AddDatasetCreateTestCase sets up a test case for the api.Client.Datasets.Create() function
func (*Service) AddDatasetDeleteTestCase ¶ added in v2.8.0
func (s *Service) AddDatasetDeleteTestCase( id string, requestHeaders, responseHeaders http.Header, ) error
AddDatasetDeleteTestCase sets up a test case for the api.Client.Datasets.Delete() function
func (*Service) AddDatasetGetReportTestCase ¶ added in v2.8.0
func (s *Service) AddDatasetGetReportTestCase( id string, reportId string, requestHeaders, responseHeaders http.Header, fileContents []byte, ) error
AddDatasetGetReportTestCase sets up a test case for the api.Client.Datasets.GetReport() function
func (*Service) AddDatasetGetTestCase ¶ added in v2.8.0
func (s *Service) AddDatasetGetTestCase( id string, requestHeaders, responseHeaders http.Header, response *dataset.Dataset, ) error
AddDatasetGetTestCase sets up a test case for the api.Client.Datasets.Get() function
func (*Service) AddDatasetListTestCase ¶ added in v2.8.0
func (s *Service) AddDatasetListTestCase( requestHeaders, responseHeaders http.Header, response []*dataset.Dataset, ) error
AddDatasetListTestCase sets up a test case for the api.Client.Datasets.List() function
func (*Service) AddDeleteVersionTestCase ¶ added in v2.7.7
func (s *Service) AddDeleteVersionTestCase( zoneName string, versionID int64, requestHeaders, responseHeaders http.Header, ) error
AddDeleteVersionTestCase sets up a test case for the api.Client.Versions.Delete() function
func (*Service) AddGlobalIPWhitelistCreateTestCase ¶ added in v2.7.9
func (s *Service) AddGlobalIPWhitelistCreateTestCase( requestHeaders, responseHeaders http.Header, whitelist, response *account.IPWhitelist, ) error
AddGlobalIPWhitelistCreateTestCase sets up a test case for the api.Client.GlobalIPWhitelist.Create() function
func (*Service) AddGlobalIPWhitelistDeleteTestCase ¶ added in v2.7.9
func (s *Service) AddGlobalIPWhitelistDeleteTestCase( whitelistID string, requestHeaders, responseHeaders http.Header, ) error
AddGlobalIPWhitelistDeleteTestCase sets up a test case for the api.Client.GlobalIPWhitelist.Delete() function
func (*Service) AddGlobalIPWhitelistGetTestCase ¶ added in v2.7.9
func (s *Service) AddGlobalIPWhitelistGetTestCase( whitelistID string, requestHeaders, responseHeaders http.Header, response *account.IPWhitelist, ) error
AddGlobalIPWhitelistGetTestCase sets up a test case for the api.Client.GlobalIPWhitelist.Get() function
func (*Service) AddGlobalIPWhitelistListTestCase ¶ added in v2.7.9
func (s *Service) AddGlobalIPWhitelistListTestCase( requestHeaders, responseHeaders http.Header, response []*account.IPWhitelist, ) error
AddGlobalIPWhitelistListTestCase sets up a test case for the api.Client.GlobalIPWhitelist.List() function
func (*Service) AddGlobalIPWhitelistUpdateTestCase ¶ added in v2.7.9
func (s *Service) AddGlobalIPWhitelistUpdateTestCase( requestHeaders, responseHeaders http.Header, whitelist, response *account.IPWhitelist, ) error
AddGlobalIPWhitelistUpdateTestCase sets up a test case for the api.Client.GlobalIPWhitelist.Update() function
func (*Service) AddPulsarJobCreateTestCase ¶
func (s *Service) AddPulsarJobCreateTestCase( requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.Job, ) error
AddPulsarJobCreateTestCase sets up a test case for the api.Client.PulsarJobs.Create() function
func (*Service) AddPulsarJobDeleteTestCase ¶
func (s *Service) AddPulsarJobDeleteTestCase( requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.Job, ) error
AddPulsarJobDeleteTestCase sets up a test case for the api.Client.PulsarJobs.Delete() function
func (*Service) AddPulsarJobGetTestCase ¶
func (s *Service) AddPulsarJobGetTestCase( appid, jobid string, requestHeaders, responseHeaders http.Header, response *pulsar.Job, ) error
AddPulsarJobGetTestCase sets up a test case for the api.Client.PulsarJobs.Get() function
func (*Service) AddPulsarJobListTestCase ¶
func (s *Service) AddPulsarJobListTestCase( appid string, requestHeaders, responseHeaders http.Header, response []*pulsar.Job, ) error
AddPulsarJobListTestCase sets up a test case for the api.Client.PulsarJobs.List() function
func (*Service) AddPulsarJobUpdateTestCase ¶
func (s *Service) AddPulsarJobUpdateTestCase( requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.Job, ) error
AddPulsarJobUpdateTestCase sets up a test case for the api.Client.PulsarJobs.Update() function
func (*Service) AddTestCase ¶
func (s *Service) AddTestCase( method, uri string, returnStatus int, requestHeaders, responseHeaders http.Header, requestBody, responseBody interface{}, ) error
AddTestCase adds a new test case to the mock service. Test cases are unique based on the method, uri, request headers, and request body.
func (*Service) AddTsigKeyCreateTestCase ¶
func (s *Service) AddTsigKeyCreateTestCase( requestHeaders, responseHeaders http.Header, tsigKey, response *dns.TSIGKey, ) error
AddTsigKeyCreateTestCase sets up a test case for the api.Client.TSIG.Create() function
func (*Service) AddTsigKeyDeleteTestCase ¶
func (s *Service) AddTsigKeyDeleteTestCase( requestHeaders, responseHeaders http.Header, tsigKey, response *dns.TSIGKey, ) error
AddTsigKeyDeleteTestCase sets up a test case for the api.Client.TSIG.Delete() function
func (*Service) AddTsigKeyGetTestCase ¶
func (s *Service) AddTsigKeyGetTestCase( name string, requestHeaders, responseHeaders http.Header, response *dns.TSIGKey, ) error
AddTsigKeyGetTestCase sets up a test case for the api.Client.TSIG.Get() function
func (*Service) AddTsigKeyListTestCase ¶
func (s *Service) AddTsigKeyListTestCase( requestHeaders, responseHeaders http.Header, response []*dns.TSIGKey, ) error
AddTsigKeyListTestCase sets up a test case for the api.Client.TSIG.List() function
func (*Service) AddTsigKeyUpdateTestCase ¶
func (s *Service) AddTsigKeyUpdateTestCase( requestHeaders, responseHeaders http.Header, tsigKey, response *dns.TSIGKey, ) error
AddTsigKeyUpdateTestCase sets up a test case for the api.Client.TSIG.Update() function
func (*Service) AddVersionListTestCase ¶ added in v2.7.7
func (s *Service) AddVersionListTestCase( zoneName string, requestHeaders, responseHeaders http.Header, response []*dns.Version, ) error
AddZoneListTestCase sets up a test case for the api.Client.Versions.List() function
func (*Service) AddZoneCreateTestCase ¶
func (s *Service) AddZoneCreateTestCase( requestHeaders, responseHeaders http.Header, zone, response *dns.Zone, ) error
AddZoneCreateTestCase sets up a test case for the api.Client.Zones.Create() function
func (*Service) AddZoneDeleteTestCase ¶
func (s *Service) AddZoneDeleteTestCase( name string, requestHeaders, responseHeaders http.Header, ) error
AddZoneDeleteTestCase sets up a test case for the api.Client.Zones.Delete() function
func (*Service) AddZoneGetTestCase ¶
func (s *Service) AddZoneGetTestCase( name string, requestHeaders, responseHeaders http.Header, response *dns.Zone, records bool, ) error
AddZoneGetTestCase sets up a test case for the api.Client.Zones.Get() function
func (*Service) AddZoneListTestCase ¶
func (s *Service) AddZoneListTestCase( requestHeaders, responseHeaders http.Header, response []*dns.Zone, ) error
AddZoneListTestCase sets up a test case for the api.Client.Zones.List() function
func (*Service) AddZoneUpdateTestCase ¶
func (s *Service) AddZoneUpdateTestCase( requestHeaders, responseHeaders http.Header, zone, response *dns.Zone, ) error
AddZoneUpdateTestCase sets up a test case for the api.Client.Zones.Update() function
func (*Service) ClearTestCases ¶
func (s *Service) ClearTestCases()
ClearTestCases removes all previously added test cases
func (*Service) NetworkGetTestCase ¶ added in v2.7.4
func (s *Service) NetworkGetTestCase( requestHeaders, responseHeaders http.Header, response []*dns.Network, ) error
NetworkGetTestCase sets up a test case for the api.Client.Network.Get() function