github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/flavors/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/flavors"
     9  
    10  	th "github.com/gophercloud/gophercloud/testhelper"
    11  	"github.com/gophercloud/gophercloud/testhelper/client"
    12  )
    13  
    14  const FlavorsListBody = `
    15  {
    16  	"flavors": [
    17          {
    18              "id": "4c82a610-8c7f-4a72-8cca-42f584e3f6d1",
    19              "name": "Basic",
    20              "description": "A basic standalone Octavia load balancer.",
    21              "enabled": true,
    22              "flavor_profile_id": "bdba88c7-beab-4fc9-a5dd-3635de59185b"
    23          },
    24  		{
    25              "id": "0af3b9cc-9284-44c2-9494-0ec337fa31bb",
    26              "name": "Advance",
    27              "description": "A advance standalone Octavia load balancer.",
    28              "enabled": false,
    29              "flavor_profile_id": "c221abc6-a845-45a0-925c-27110c9d7bdc"
    30          }
    31      ]
    32  }
    33  `
    34  
    35  const SingleFlavorBody = `
    36  {
    37  	"flavor": {
    38  		"id": "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
    39  		"name": "Basic",
    40  		"description": "A basic standalone Octavia load balancer.",
    41  		"enabled": true,
    42  		"flavor_profile_id": "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1"
    43  	}
    44  }
    45  `
    46  
    47  const PostUpdateFlavorBody = `
    48  {
    49  	"flavor": {
    50  		"id": "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
    51  		"name": "Basic v2",
    52  		"description": "Rename flavor",
    53  		"enabled": false,
    54  		"flavor_profile_id": "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1"
    55  	}
    56  }
    57  `
    58  
    59  var (
    60  	FlavorBasic = flavors.Flavor{
    61  		ID:              "4c82a610-8c7f-4a72-8cca-42f584e3f6d1",
    62  		Name:            "Basic",
    63  		Description:     "A basic standalone Octavia load balancer.",
    64  		Enabled:         true,
    65  		FlavorProfileId: "bdba88c7-beab-4fc9-a5dd-3635de59185b",
    66  	}
    67  
    68  	FlavorAdvance = flavors.Flavor{
    69  		ID:              "0af3b9cc-9284-44c2-9494-0ec337fa31bb",
    70  		Name:            "Advance",
    71  		Description:     "A advance standalone Octavia load balancer.",
    72  		Enabled:         false,
    73  		FlavorProfileId: "c221abc6-a845-45a0-925c-27110c9d7bdc",
    74  	}
    75  
    76  	FlavorDb = flavors.Flavor{
    77  		ID:              "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
    78  		Name:            "Basic",
    79  		Description:     "A basic standalone Octavia load balancer.",
    80  		Enabled:         true,
    81  		FlavorProfileId: "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1",
    82  	}
    83  
    84  	FlavorUpdated = flavors.Flavor{
    85  		ID:              "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
    86  		Name:            "Basic v2",
    87  		Description:     "Rename flavor",
    88  		Enabled:         false,
    89  		FlavorProfileId: "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1",
    90  	}
    91  )
    92  
    93  func HandleFlavorListSuccessfully(t *testing.T) {
    94  	th.Mux.HandleFunc("/v2.0/lbaas/flavors", func(w http.ResponseWriter, r *http.Request) {
    95  		th.TestMethod(t, r, "GET")
    96  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    97  
    98  		w.Header().Add("Content-Type", "application/json")
    99  		r.ParseForm()
   100  		marker := r.Form.Get("marker")
   101  		switch marker {
   102  		case "":
   103  			fmt.Fprintf(w, FlavorsListBody)
   104  		case "3a0d060b-fcec-4250-9ab6-940b806a12dd":
   105  			fmt.Fprintf(w, `{ "flavors": [] }`)
   106  		default:
   107  			t.Fatalf("/v2.0/lbaas/flavors invoked with unexpected marker=[%s]", marker)
   108  		}
   109  	})
   110  }
   111  
   112  func HandleFlavorCreationSuccessfully(t *testing.T, response string) {
   113  	th.Mux.HandleFunc("/v2.0/lbaas/flavors", func(w http.ResponseWriter, r *http.Request) {
   114  		th.TestMethod(t, r, "POST")
   115  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   116  		th.TestJSONRequest(t, r, `{
   117  			"flavor": {
   118  				"name": "Basic",
   119  				"description": "A basic standalone Octavia load balancer.",
   120  				"enabled": true,
   121  				"flavor_profile_id": "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1"
   122  			}
   123  		}`)
   124  
   125  		w.WriteHeader(http.StatusAccepted)
   126  		w.Header().Add("Content-Type", "application/json")
   127  		fmt.Fprintf(w, response)
   128  	})
   129  }
   130  
   131  func HandleFlavorGetSuccessfully(t *testing.T) {
   132  	th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
   133  		th.TestMethod(t, r, "GET")
   134  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   135  		th.TestHeader(t, r, "Accept", "application/json")
   136  
   137  		fmt.Fprintf(w, SingleFlavorBody)
   138  	})
   139  }
   140  
   141  func HandleFlavorDeletionSuccessfully(t *testing.T) {
   142  	th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
   143  		th.TestMethod(t, r, "DELETE")
   144  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   145  
   146  		w.WriteHeader(http.StatusNoContent)
   147  	})
   148  }
   149  
   150  func HandleFlavorUpdateSuccessfully(t *testing.T) {
   151  	th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
   152  		th.TestMethod(t, r, "PUT")
   153  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   154  		th.TestHeader(t, r, "Accept", "application/json")
   155  		th.TestHeader(t, r, "Content-Type", "application/json")
   156  		th.TestJSONRequest(t, r, `{
   157  			"flavor": {
   158  				"name": "Basic v2",
   159  				"description": "Rename flavor",
   160  				"enabled": true
   161  			}
   162  		}`)
   163  
   164  		fmt.Fprintf(w, PostUpdateFlavorBody)
   165  	})
   166  }