github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/vbs/v2/backups/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk"
     9  	"github.com/huaweicloud/golangsdk/openstack/vbs/v2/backups"
    10  	fake "github.com/huaweicloud/golangsdk/openstack/vbs/v2/common"
    11  	th "github.com/huaweicloud/golangsdk/testhelper"
    12  )
    13  
    14  // ListExpected represents the expected object from a List request.
    15  var ListExpected = []backups.Backup{
    16  	{
    17  		Name:             "c2c-test-buckup",
    18  		Id:               "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    19  		Status:           "available",
    20  		ObjectCount:      0,
    21  		TenantId:         "17fbda95add24720a4038ba4b1c705ed",
    22  		Container:        "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    23  		AvailabilityZone: "eu-de-01",
    24  		DependentBackups: false,
    25  		SnapshotId:       "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    26  		VolumeId:         "5024a06e-6990-4f12-9dcc-8fe26b01a710",
    27  		Incremental:      false,
    28  		Size:             10,
    29  		Links: []golangsdk.Link{
    30  			{
    31  				Href: "https://vbs.eu-de.otc.t-systems.com/v2/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507",
    32  				Rel:  "self",
    33  			},
    34  			{
    35  				Href: "https://vbs.eu-de.otc.t-systems.com/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507",
    36  				Rel:  "bookmark",
    37  			},
    38  		},
    39  	},
    40  }
    41  
    42  // FullListOutput represents the response body from a List request.
    43  const FullListOutput = `
    44  {
    45      "backups": [
    46          {
    47              "status": "available",
    48              "object_count": 0,
    49              "os-bak-tenant-attr:tenant_id": "17fbda95add24720a4038ba4b1c705ed",
    50              "container": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    51              "name": "c2c-test-buckup",
    52              "links": [
    53                  {
    54                      "href": "https://vbs.eu-de.otc.t-systems.com/v2/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507",
    55                      "rel": "self"
    56                  },
    57                  {
    58                      "href": "https://vbs.eu-de.otc.t-systems.com/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507",
    59                      "rel": "bookmark"
    60                  }
    61              ],
    62              "availability_zone": "eu-de-01",
    63              "has_dependent_backups": false,
    64              "snapshot_id": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    65              "volume_id": "5024a06e-6990-4f12-9dcc-8fe26b01a710",
    66              "is_incremental": false,
    67              "id": "87566ed6-72cb-4053-aa6e-6f6216b3d507",
    68              "size": 10
    69          }
    70  	]
    71  }`
    72  
    73  // HandleListSuccessfully creates an HTTP handler at `/backups/detail` on the test handler mux
    74  // that responds with a `List` response.
    75  func HandleListSuccessfully(t *testing.T, output string) {
    76  	th.Mux.HandleFunc("/backups/detail", func(w http.ResponseWriter, r *http.Request) {
    77  		th.TestMethod(t, r, "GET")
    78  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
    79  		w.Header().Add("Content-Type", "application/json")
    80  		w.WriteHeader(http.StatusOK)
    81  		fmt.Fprintf(w, output)
    82  	})
    83  }
    84  
    85  // getResponse represents the response body from a Get request.
    86  var getResponse = `{
    87      "backup": {
    88              "status": "available",
    89              "object_count": 0,
    90              "os-bak-tenant-attr:tenant_id": "17fbda95add24720a4038ba4b1c705ed",
    91              "container": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
    92              "name": "c2c-test-buckup",
    93              "links": [
    94                  {
    95                      "href": "https://vbs.eu-de.otc.t-systems.com/v2/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507",
    96                      "rel": "self"
    97                  },
    98                  {
    99                      "href": "https://vbs.eu-de.otc.t-systems.com/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507",
   100                      "rel": "bookmark"
   101                  }
   102              ],
   103              "availability_zone": "eu-de-01",
   104              "has_dependent_backups": false,
   105              "snapshot_id": "a704c75f-f0d1-4efa-9fd6-7557fe1ee8d3",
   106              "volume_id": "5024a06e-6990-4f12-9dcc-8fe26b01a710",
   107              "is_incremental": false,
   108              "id": "87566ed6-72cb-4053-aa6e-6f6216b3d507",
   109              "size": 10
   110          }
   111  }`
   112  
   113  // HandleGetSuccessfully creates an HTTP handler at `/17fbda95add24720a4038ba4b1c705ed/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507`
   114  // on the test handler mux that responds with a `Get` response.
   115  func HandleGetSuccessfully(t *testing.T) {
   116  	th.Mux.HandleFunc("/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507", func(w http.ResponseWriter, r *http.Request) {
   117  		th.TestMethod(t, r, "GET")
   118  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   119  		w.Header().Add("Content-Type", "application/json")
   120  		w.WriteHeader(http.StatusOK)
   121  		fmt.Fprintf(w, getResponse)
   122  	})
   123  }
   124  
   125  // CreateExpected represents the expected object from a Create request.
   126  var CreateExpected = &backups.JobResponse{
   127  	JobID: "ff8080826576401e01657b99fc444986",
   128  }
   129  
   130  // CreateOutput represents the response body from a Create request.
   131  const CreateOutput = `{
   132      "job_id": "ff8080826576401e01657b99fc444986"
   133  }`
   134  
   135  // HandleCreateSuccessfully creates an HTTP handler at `/backups` on the test handler mux
   136  // that responds with a `Create` response.
   137  func HandleCreateSuccessfully(t *testing.T, output string) {
   138  	th.Mux.HandleFunc("/cloudbackups", func(w http.ResponseWriter, r *http.Request) {
   139  		th.TestMethod(t, r, "POST")
   140  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   141  		th.TestHeader(t, r, "Accept", "application/json")
   142  		w.Header().Set("Content-Type", "application/json")
   143  		w.WriteHeader(http.StatusOK)
   144  		fmt.Fprintf(w, output)
   145  	})
   146  }
   147  
   148  // HandleDeleteSuccessfully creates an HTTP handler at `/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507`
   149  // on the test handler mux that responds with a `Delete` response.
   150  func HandleDeleteSuccessfully(t *testing.T) {
   151  	th.Mux.HandleFunc("/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507", func(w http.ResponseWriter, r *http.Request) {
   152  		th.TestMethod(t, r, "DELETE")
   153  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   154  		w.WriteHeader(http.StatusAccepted)
   155  	})
   156  }
   157  
   158  // CreateExpected represents the expected object from a Create request.
   159  var RestoreExpected = &backups.BackupRestoreInfo{
   160  	BackupId:   "87566ed6-72cb-4053-aa6e-6f6216b3d507",
   161  	VolumeName: "c2c-test-disk",
   162  	VolumeId:   "5024a06e-6990-4f12-9dcc-8fe26b01a710",
   163  }
   164  
   165  // RestoreOutput represents the response body from a Create request.
   166  const RestoreOutput = `
   167  {
   168      "restore": {
   169          "backup_id": "87566ed6-72cb-4053-aa6e-6f6216b3d507",
   170          "volume_name": "c2c-test-disk",
   171          "volume_id": "5024a06e-6990-4f12-9dcc-8fe26b01a710"
   172      }
   173  }`
   174  
   175  // HandleRestoreSuccessfully creates an HTTP handler at `/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507/restore` on the test handler mux
   176  // that responds with a `Create` response.
   177  func HandleRestoreSuccessfully(t *testing.T, output string) {
   178  	th.Mux.HandleFunc("/backups/87566ed6-72cb-4053-aa6e-6f6216b3d507/restore", func(w http.ResponseWriter, r *http.Request) {
   179  		th.TestMethod(t, r, "POST")
   180  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   181  		th.TestHeader(t, r, "Content-Type", "application/json")
   182  		th.TestHeader(t, r, "Accept", "application/json")
   183  		w.WriteHeader(http.StatusAccepted)
   184  		fmt.Fprintf(w, output)
   185  	})
   186  }