github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/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/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/flavors"
     9  
    10  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    11  	"github.com/vnpaycloud-console/gophercloud/v2/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  		if err := r.ParseForm(); err != nil {
   100  			t.Errorf("Failed to parse request form %v", err)
   101  		}
   102  		marker := r.Form.Get("marker")
   103  		switch marker {
   104  		case "":
   105  			fmt.Fprint(w, FlavorsListBody)
   106  		case "3a0d060b-fcec-4250-9ab6-940b806a12dd":
   107  			fmt.Fprint(w, `{ "flavors": [] }`)
   108  		default:
   109  			t.Fatalf("/v2.0/lbaas/flavors invoked with unexpected marker=[%s]", marker)
   110  		}
   111  	})
   112  }
   113  
   114  func HandleFlavorCreationSuccessfully(t *testing.T, response string) {
   115  	th.Mux.HandleFunc("/v2.0/lbaas/flavors", func(w http.ResponseWriter, r *http.Request) {
   116  		th.TestMethod(t, r, "POST")
   117  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   118  		th.TestJSONRequest(t, r, `{
   119  			"flavor": {
   120  				"name": "Basic",
   121  				"description": "A basic standalone Octavia load balancer.",
   122  				"enabled": true,
   123  				"flavor_profile_id": "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1"
   124  			}
   125  		}`)
   126  
   127  		w.WriteHeader(http.StatusAccepted)
   128  		w.Header().Add("Content-Type", "application/json")
   129  		fmt.Fprint(w, response)
   130  	})
   131  }
   132  
   133  func HandleFlavorGetSuccessfully(t *testing.T) {
   134  	th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
   135  		th.TestMethod(t, r, "GET")
   136  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   137  		th.TestHeader(t, r, "Accept", "application/json")
   138  
   139  		fmt.Fprint(w, SingleFlavorBody)
   140  	})
   141  }
   142  
   143  func HandleFlavorDeletionSuccessfully(t *testing.T) {
   144  	th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
   145  		th.TestMethod(t, r, "DELETE")
   146  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   147  
   148  		w.WriteHeader(http.StatusNoContent)
   149  	})
   150  }
   151  
   152  func HandleFlavorUpdateSuccessfully(t *testing.T) {
   153  	th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
   154  		th.TestMethod(t, r, "PUT")
   155  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   156  		th.TestHeader(t, r, "Accept", "application/json")
   157  		th.TestHeader(t, r, "Content-Type", "application/json")
   158  		th.TestJSONRequest(t, r, `{
   159  			"flavor": {
   160  				"name": "Basic v2",
   161  				"description": "Rename flavor",
   162  				"enabled": true
   163  			}
   164  		}`)
   165  
   166  		fmt.Fprint(w, PostUpdateFlavorBody)
   167  	})
   168  }