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) 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) AddDNSViewCreateTestCase(requestHeaders, responseHeaders http.Header, dnsView, response *dns.DNSView) 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.DNSView) error
- func (s *Service) AddDNSViewUpdatePreferencesTestCase(requestHeaders, responseHeaders http.Header, body, response interface{}) error
- func (s *Service) AddDNSViewUpdateTestCase(requestHeaders, responseHeaders http.Header, dnsView, response *dns.DNSView) error
- func (s *Service) AddPulsarJobCreateTestCase(requestHeaders, responseHeaders http.Header, ...) error
- func (s *Service) AddPulsarJobDeleteTestCase(requestHeaders, responseHeaders http.Header, ...) 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, ...) 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) 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) 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) 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) AddDNSViewCreateTestCase ¶
func (s *Service) AddDNSViewCreateTestCase( requestHeaders, responseHeaders http.Header, dnsView, response *dns.DNSView, ) 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.DNSView, ) 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.DNSView, ) 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
AddDNSViewGetPreferencesTestCase 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.DNSView, ) error
AddDNSViewUpdateTestCase sets up a test case for the api.Client.View.Update() function
func (*Service) AddPulsarJobCreateTestCase ¶
func (s *Service) AddPulsarJobCreateTestCase( requestHeaders, responseHeaders http.Header, pulsarJob, response *pulsar.PulsarJob, ) error
AddPulsarJobGetTestCase 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.PulsarJob, ) error
AddPulsarJobGetTestCase 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.PulsarJob, ) 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.PulsarJob, ) 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.PulsarJob, ) error
AddPulsarJobGetTestCase 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) 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, ) 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