github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/events/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/gophercloud/gophercloud/openstack/clustering/v1/events"
    10  
    11  	th "github.com/gophercloud/gophercloud/testhelper"
    12  	fake "github.com/gophercloud/gophercloud/testhelper/client"
    13  )
    14  
    15  const ListResponse = `
    16  {
    17  	"events": [
    18  		{
    19  			"action": "CLUSTER_CREATE",
    20  			"cluster": null,
    21  			"cluster_id": null,
    22  			"id": "edce3528-864f-41fb-8759-f4707925cc09",
    23  			"level": "INFO",
    24  			"meta_data": {},
    25  			"oid": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
    26  			"oname": "cluster001",
    27  			"otype": "CLUSTER",
    28  			"project": "f1fe61dcda2f4618a14c10dc7abc214d",
    29  			"status": "start",
    30  			"status_reason": "Initializing",
    31  			"timestamp": "2015-03-05T08:53:15Z",
    32  			"user": "8bcd2cdca7684c02afc9e4f2fc0f0c79"
    33  		},
    34  		{
    35  			"action": "NODE_DELETE",
    36  			"cluster": null,
    37  			"cluster_id": null,
    38  			"id": "abcd1234-864f-41fb-8759-f4707925dd10",
    39  			"level": "INFO",
    40  			"meta_data": {},
    41  			"oid": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
    42  			"oname": "node119",
    43  			"otype": "node",
    44  			"project": "f1fe61dcda2f4618a14c10dc7abc214d",
    45  			"status": "start",
    46  			"status_reason": "84492c96",
    47  			"timestamp": "2015-03-06T18:53:15Z",
    48  			"user": "8bcd2cdca7684c02afc9e4f2fc0f0c79"
    49  		}
    50  	]
    51  }
    52  `
    53  
    54  const GetResponse = `
    55  {
    56  	"event": {
    57  		"action": "CLUSTER_CREATE",
    58  		"cluster_id": null,
    59  		"id": "edce3528-864f-41fb-8759-f4707925cc09",
    60  		"level": "INFO",
    61  		"meta_data": {},
    62  		"oid": "0df0931b-e251-4f2e-8719-4ebfda3627ba",
    63  		"oname": "cluster001",
    64  		"otype": "CLUSTER",
    65  		"project": "f1fe61dcda2f4618a14c10dc7abc214d",
    66  		"status": "start",
    67  		"status_reason": "Initializing",
    68  		"timestamp": "2015-03-05T08:53:15Z",
    69  		"user": "8bcd2cdca7684c02afc9e4f2fc0f0c79"
    70  	}
    71  }
    72  `
    73  
    74  var ExpectedEvent1 = events.Event{
    75  	Action:       "CLUSTER_CREATE",
    76  	Cluster:      "",
    77  	ClusterID:    "",
    78  	ID:           "edce3528-864f-41fb-8759-f4707925cc09",
    79  	Level:        "INFO",
    80  	Metadata:     map[string]interface{}{},
    81  	OID:          "0df0931b-e251-4f2e-8719-4ebfda3627ba",
    82  	OName:        "cluster001",
    83  	OType:        "CLUSTER",
    84  	Project:      "f1fe61dcda2f4618a14c10dc7abc214d",
    85  	Status:       "start",
    86  	StatusReason: "Initializing",
    87  	Timestamp:    time.Date(2015, 3, 5, 8, 53, 15, 0, time.UTC),
    88  	User:         "8bcd2cdca7684c02afc9e4f2fc0f0c79",
    89  }
    90  
    91  var ExpectedEvent2 = events.Event{
    92  	Action:       "NODE_DELETE",
    93  	Cluster:      "",
    94  	ClusterID:    "",
    95  	ID:           "abcd1234-864f-41fb-8759-f4707925dd10",
    96  	Level:        "INFO",
    97  	Metadata:     map[string]interface{}{},
    98  	OID:          "0df0931b-e251-4f2e-8719-4ebfda3627ba",
    99  	OName:        "node119",
   100  	OType:        "node",
   101  	Project:      "f1fe61dcda2f4618a14c10dc7abc214d",
   102  	Status:       "start",
   103  	StatusReason: "84492c96",
   104  	Timestamp:    time.Date(2015, 3, 6, 18, 53, 15, 0, time.UTC),
   105  	User:         "8bcd2cdca7684c02afc9e4f2fc0f0c79",
   106  }
   107  
   108  var ExpectedEvents = []events.Event{ExpectedEvent1, ExpectedEvent2}
   109  
   110  func HandleListSuccessfully(t *testing.T) {
   111  	th.Mux.HandleFunc("/v1/events", func(w http.ResponseWriter, r *http.Request) {
   112  		th.TestMethod(t, r, "GET")
   113  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   114  
   115  		w.Header().Add("Content-Type", "application/json")
   116  		w.WriteHeader(http.StatusOK)
   117  		fmt.Fprintf(w, ListResponse)
   118  	})
   119  }
   120  
   121  func HandleGetSuccessfully(t *testing.T, id string) {
   122  	th.Mux.HandleFunc("/v1/events/"+id, func(w http.ResponseWriter, r *http.Request) {
   123  		th.TestMethod(t, r, "GET")
   124  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   125  
   126  		w.Header().Add("Content-Type", "application/json")
   127  		w.WriteHeader(http.StatusOK)
   128  
   129  		fmt.Fprintf(w, GetResponse)
   130  	})
   131  }