testing

package
v1.0.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

zones unit tests

package testing

import (

"fmt"
"net/http"
"testing"
"time"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/dns/v2/zones"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"

)

// List Output is a sample response to a List call. const ListOutput = `

{
    "links": {
      "self": "http://example.com:9001/v2/zones"
    },
    "metadata": {
      "total_count": 2
    },
    "zones": [
        {
            "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
            "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
            "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
            "name": "example.org.",
            "email": "joe@example.org",
            "ttl": 7200,
            "serial": 1404757531,
            "status": "ACTIVE",
            "action": "CREATE",
            "description": "This is an example zone.",
            "masters": [],
            "type": "PRIMARY",
            "transferred_at": null,
            "version": 1,
            "created_at": "2014-07-07T18:25:31.275934",
            "updated_at": null,
            "links": {
              "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
            }
        },
        {
            "id": "34c4561c-9205-4386-9df5-167436f5a222",
            "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
            "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
            "name": "foo.example.com.",
            "email": "joe@foo.example.com",
            "ttl": 7200,
            "serial": 1488053571,
            "status": "ACTIVE",
            "action": "CREATE",
            "description": "This is another example zone.",
            "masters": ["example.com."],
            "type": "PRIMARY",
            "transferred_at": null,
            "version": 1,
            "created_at": "2014-07-07T18:25:31.275934",
            "updated_at": "2015-02-25T20:23:01.234567",
            "links": {
              "self": "https://127.0.0.1:9001/v2/zones/34c4561c-9205-4386-9df5-167436f5a222"
            }
        }
    ]
}

`

// GetOutput is a sample response to a Get call. const GetOutput = `

{
    "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
    "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
    "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
    "name": "example.org.",
    "email": "joe@example.org",
    "ttl": 7200,
    "serial": 1404757531,
    "status": "ACTIVE",
    "action": "CREATE",
    "description": "This is an example zone.",
    "masters": [],
    "type": "PRIMARY",
    "transferred_at": null,
    "version": 1,
    "created_at": "2014-07-07T18:25:31.275934",
    "updated_at": null,
    "links": {
      "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
    }
}

`

// FirstZone is the first result in ListOutput var FirstZoneCreatedAt, _ = time.Parse(gophercloud.RFC3339MilliNoZ, "2014-07-07T18:25:31.275934")

var FirstZone = zones.Zone{
	ID:          "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
	PoolID:      "572ba08c-d929-4c70-8e42-03824bb24ca2",
	ProjectID:   "4335d1f0-f793-11e2-b778-0800200c9a66",
	Name:        "example.org.",
	Email:       "joe@example.org",
	TTL:         7200,
	Serial:      1404757531,
	Status:      "ACTIVE",
	Action:      "CREATE",
	Description: "This is an example zone.",
	Masters:     []string{},
	Type:        "PRIMARY",
	Version:     1,
	CreatedAt:   FirstZoneCreatedAt,
	Links: map[string]interface{}{
		"self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
	},
}

var SecondZoneCreatedAt, _ = time.Parse(gophercloud.RFC3339MilliNoZ, "2014-07-07T18:25:31.275934") var SecondZoneUpdatedAt, _ = time.Parse(gophercloud.RFC3339MilliNoZ, "2015-02-25T20:23:01.234567")

var SecondZone = zones.Zone{
	ID:          "34c4561c-9205-4386-9df5-167436f5a222",
	PoolID:      "572ba08c-d929-4c70-8e42-03824bb24ca2",
	ProjectID:   "4335d1f0-f793-11e2-b778-0800200c9a66",
	Name:        "foo.example.com.",
	Email:       "joe@foo.example.com",
	TTL:         7200,
	Serial:      1488053571,
	Status:      "ACTIVE",
	Action:      "CREATE",
	Description: "This is another example zone.",
	Masters:     []string{"example.com."},
	Type:        "PRIMARY",
	Version:     1,
	CreatedAt:   SecondZoneCreatedAt,
	UpdatedAt:   SecondZoneUpdatedAt,
	Links: map[string]interface{}{
		"self": "https://127.0.0.1:9001/v2/zones/34c4561c-9205-4386-9df5-167436f5a222",
	},
}

// ExpectedZonesSlice is the slice of results that should be parsed // from ListOutput, in the expected order. var ExpectedZonesSlice = []zones.Zone{FirstZone, SecondZone}

// HandleListSuccessfully configures the test server to respond to a List request.

func HandleListSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/zones", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Add("Content-Type", "application/json")
		fmt.Fprintf(w, ListOutput)
	})
}

// HandleGetSuccessfully configures the test server to respond to a List request.

func HandleGetSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Add("Content-Type", "application/json")
		fmt.Fprintf(w, GetOutput)
	})
}

// CreateZoneRequest is a sample request to create a zone. const CreateZoneRequest = `

{
    "name": "example.org.",
    "email": "joe@example.org",
    "type": "PRIMARY",
    "ttl": 7200,
    "description": "This is an example zone."
}

`

// CreateZoneResponse is a sample response to a create request. const CreateZoneResponse = `

{
    "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
    "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
    "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
    "name": "example.org.",
    "email": "joe@example.org",
    "ttl": 7200,
    "serial": 1404757531,
    "status": "ACTIVE",
    "action": "CREATE",
    "description": "This is an example zone.",
    "masters": [],
    "type": "PRIMARY",
    "transferred_at": null,
    "version": 1,
    "created_at": "2014-07-07T18:25:31.275934",
    "updated_at": null,
    "links": {
      "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
    }
}

`

// CreatedZone is the expected created zone var CreatedZone = FirstZone

// HandleZoneCreationSuccessfully configures the test server to respond to a Create request.

func HandleCreateSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/zones", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
		th.TestJSONRequest(t, r, CreateZoneRequest)

		w.WriteHeader(http.StatusCreated)
		w.Header().Add("Content-Type", "application/json")
		fmt.Fprintf(w, CreateZoneResponse)
	})
}

// UpdateZoneRequest is a sample request to update a zone. const UpdateZoneRequest = `

{
    "ttl": 600,
    "description": "Updated Description"
}

`

// UpdateZoneResponse is a sample response to update a zone. const UpdateZoneResponse = `

{
    "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
    "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
    "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
    "name": "example.org.",
    "email": "joe@example.org",
    "ttl": 600,
    "serial": 1404757531,
    "status": "PENDING",
    "action": "UPDATE",
    "description": "Updated Description",
    "masters": [],
    "type": "PRIMARY",
    "transferred_at": null,
    "version": 1,
    "created_at": "2014-07-07T18:25:31.275934",
    "updated_at": null,
    "links": {
      "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
    }
}

`

// HandleZoneUpdateSuccessfully configures the test server to respond to an Update request.

func HandleUpdateSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
		func(w http.ResponseWriter, r *http.Request) {
			th.TestMethod(t, r, "PATCH")
			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
			th.TestJSONRequest(t, r, UpdateZoneRequest)

			w.WriteHeader(http.StatusOK)
			w.Header().Add("Content-Type", "application/json")
			fmt.Fprintf(w, UpdateZoneResponse)
		})
}

// DeleteZoneResponse is a sample response to update a zone. const DeleteZoneResponse = `

{
    "id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
    "pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2",
    "project_id": "4335d1f0-f793-11e2-b778-0800200c9a66",
    "name": "example.org.",
    "email": "joe@example.org",
    "ttl": 600,
    "serial": 1404757531,
    "status": "PENDING",
    "action": "DELETE",
    "description": "Updated Description",
    "masters": [],
    "type": "PRIMARY",
    "transferred_at": null,
    "version": 1,
    "created_at": "2014-07-07T18:25:31.275934",
    "updated_at": null,
    "links": {
      "self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
    }
}

`

// HandleZoneDeleteSuccessfully configures the test server to respond to an Delete request.

func HandleDeleteSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",
		func(w http.ResponseWriter, r *http.Request) {
			th.TestMethod(t, r, "DELETE")
			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

			w.WriteHeader(http.StatusAccepted)
			w.Header().Add("Content-Type", "application/json")
			fmt.Fprintf(w, DeleteZoneResponse)
		})
}

Index

Constants

View Source
const CreateZoneRequest = `` /* 233-byte string literal not displayed */

CreateZoneRequest is a sample request to create a zone.

View Source
const CreateZoneResponse = `` /* 742-byte string literal not displayed */

CreateZoneResponse is a sample response to a create request.

View Source
const DeleteZoneResponse = `` /* 898-byte string literal not displayed */

DeleteZoneResponse is a sample response to update a zone.

View Source
const GetOutput = `` /* 902-byte string literal not displayed */

GetOutput is a sample response to a Get call.

View Source
const ListOutput = `` /* 1672-byte string literal not displayed */

List Output is a sample response to a List call.

View Source
const UpdateZoneRequest = `
{
    "ttl": 600,
    "description": "Updated Description"
}
`

UpdateZoneRequest is a sample request to update a zone.

View Source
const UpdateZoneResponse = `` /* 627-byte string literal not displayed */

UpdateZoneResponse is a sample response to update a zone.

Variables

View Source
var CreatedZone = zones.ZoneCreateResponse{
	ID:          "ff8080825b8fc86c015b94bc6f8712c3",
	Name:        "example.com.",
	Email:       "xx@example.com",
	Serial:      0,
	Status:      "ACTIVE",
	Description: "This is an example zone.",
	Masters:     []string{},
	CreatedAt:   "2017-04-22T08:17:08.997",
	UpdatedAt:   "2017-04-22T08:17:09.997",
	TTL:         300,
	Links: zones.Link{
		Self: "https://Endpoint/v2/zones/ff8080825b8fc86c015b94bc6f8712c3",
	},
	PoolId:    "ff8080825ab738f4015ab7513298010e",
	ProjectId: "e55c6f3dc4e34c9f86353b664ae0e70c",
	ZoneType:  "private",
	RecordNum: 2,
	Router: zones.AssociateRouterResponse{
		RouterId:     "19664294-0bf6-4271-ad3a-94b8c79c6558",
		Status:       "ACTIVE",
		RouterRegion: "xx",
	},
}

CreatedZone is the expected created zone

View Source
var ExpectedZonesSlice = []zones.Zone{FirstZone, SecondZone}

ExpectedZonesSlice is the slice of results that should be parsed from ListOutput, in the expected order.

View Source
var FirstZone = zones.Zone{
	ID:          "ff8080825b8fc86c015b94bc6f8712c3",
	Name:        "example.com.",
	Email:       "xx@example.com",
	Serial:      0,
	Status:      "ACTIVE",
	Description: "This is an example zone.",
	Masters:     []string{},
	CreatedAt:   "2017-04-22T08:17:08.997",
	UpdatedAt:   "2017-04-22T08:17:09.997",
	TTL:         300,
	Links: zones.Link{
		Self: "https://Endpoint/v2/zones/ff8080825b8fc86c015b94bc6f8712c3",
	},
	PoolId:    "ff8080825ab738f4015ab7513298010e",
	ProjectId: "e55c6f3dc4e34c9f86353b664ae0e70c",
	ZoneType:  "private",
	RecordNum: 2,
	Routers: []zones.AssociateRouterResponse{
		{
			RouterId:     "19664294-0bf6-4271-ad3a-94b8c79c6558",
			Status:       "ACTIVE",
			RouterRegion: "xx",
		},
		{
			RouterId:     "f0791650-db8c-4a20-8a44-a06c6e24b15b",
			Status:       "ACTIVE",
			RouterRegion: "xx",
		},
	},
}
View Source
var SecondZone = zones.Zone{
	ID:          "ff8080825b8fc86c015b94bc6f871223",
	Name:        "example.com.",
	Email:       "xx@example.com",
	Serial:      0,
	Status:      "ACTIVE",
	Description: "This is an example zone.",
	Masters:     []string{},
	CreatedAt:   "2017-04-22T08:17:08.997",
	UpdatedAt:   "2017-04-22T08:17:09.997",
	TTL:         300,
	Links: zones.Link{
		Self: "https://Endpoint/v2/zones/ff8080825b8fc86c015b94bc6f8712c3",
	},
	PoolId:    "ff8080825ab738f4015ab7513298010e",
	ProjectId: "e55c6f3dc4e34c9f86353b664ae0e70c",
	ZoneType:  "private",
	RecordNum: 2,
	Routers: []zones.AssociateRouterResponse{
		{
			RouterId:     "19664294-0bf6-4271-ad3a-94b8c79c6558",
			Status:       "ACTIVE",
			RouterRegion: "xx",
		},
		{
			RouterId:     "f0791650-db8c-4a20-8a44-a06c6e24b15b",
			Status:       "ACTIVE",
			RouterRegion: "xx",
		},
	},
}

Functions

func HandleCreateSuccessfully

func HandleCreateSuccessfully(t *testing.T)

HandleZoneCreationSuccessfully configures the test server to respond to a Create request.

func HandleDeleteSuccessfully

func HandleDeleteSuccessfully(t *testing.T)

HandleZoneDeleteSuccessfully configures the test server to respond to an Delete request.

func HandleGetSuccessfully

func HandleGetSuccessfully(t *testing.T)

HandleGetSuccessfully configures the test server to respond to a List request.

func HandleListSuccessfully

func HandleListSuccessfully(t *testing.T)

HandleListSuccessfully configures the test server to respond to a List request.

func HandleUpdateSuccessfully

func HandleUpdateSuccessfully(t *testing.T)

HandleZoneUpdateSuccessfully configures the test server to respond to an Update request.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL