github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cbr/v3/tasks/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/cbr/v3/tasks"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedGetResponse = `
    15  {
    16    "operation_log" : {
    17      "status" : "success",
    18      "provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66",
    19      "checkpoint_id" : "b432511f-d889-428f-8b0e-5f47c524c6b6",
    20      "updated_at" : "2019-05-23T14:35:23.584418",
    21      "error_info" : {
    22        "message" : "",
    23        "code" : ""
    24      },
    25      "started_at" : "2019-05-23T14:31:36.007230",
    26      "id" : "4827f2da-b008-4507-ab7d-42d0df5ed912",
    27      "extra_info" : {
    28        "resource" : {
    29          "type" : "OS::Nova::Server",
    30          "id" : "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
    31          "name" : "ECS-0001"
    32        },
    33        "backup" : {
    34          "backup_name" : "manualbk_1234",
    35          "backup_id" : "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1"
    36        },
    37        "common" : {
    38          "progress" : 100,
    39          "request_id" : "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc"
    40        }
    41      },
    42      "ended_at" : "2019-05-23T14:35:23.511155",
    43      "created_at" : "2019-05-23T14:31:36.039365",
    44      "operation_type" : "backup",
    45      "project_id" : "04f1829c788037ac2fb8c01eb2b04b95"
    46    }
    47  }`
    48  
    49  	expectedListResponse = `
    50  {
    51    "operation_logs" : [ {
    52      "status" : "success",
    53      "provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66",
    54      "checkpoint_id" : "b432511f-d889-428f-8b0e-5f47c524c6b6",
    55      "updated_at" : "2019-05-23T14:35:23.584418",
    56      "error_info" : {
    57        "message" : "",
    58        "code" : ""
    59      },
    60      "started_at" : "2019-05-23T14:31:36.007230",
    61      "id" : "4827f2da-b008-4507-ab7d-42d0df5ed912",
    62      "extra_info" : {
    63        "resource" : {
    64          "type" : "OS::Nova::Server",
    65          "id" : "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
    66          "name" : "ECS-0001"
    67        },
    68        "backup" : {
    69          "backup_name" : "manualbk_1234",
    70          "backup_id" : "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1"
    71        },
    72        "common" : {
    73          "progress" : 100,
    74          "request_id" : "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc"
    75        }
    76      },
    77      "ended_at" : "2019-05-23T14:35:23.511155",
    78      "created_at" : "2019-05-23T14:31:36.039365",
    79      "operation_type" : "backup",
    80      "project_id" : "04f1829c788037ac2fb8c01eb2b04b95"
    81    } ],
    82    "count" : 1
    83  }`
    84  )
    85  
    86  var (
    87  	expectedGetResponseData = &tasks.OperationLog{
    88  		Status:       "success",
    89  		ProviderID:   "0daac4c5-6707-4851-97ba-169e36266b66",
    90  		CheckpointID: "b432511f-d889-428f-8b0e-5f47c524c6b6",
    91  		UpdatedAt:    "2019-05-23T14:35:23.584418",
    92  		ErrorInfo: tasks.OpErrorInfo{
    93  			Message: "",
    94  			Code:    "",
    95  		},
    96  		StartedAt: "2019-05-23T14:31:36.007230",
    97  		ID:        "4827f2da-b008-4507-ab7d-42d0df5ed912",
    98  		ExtraInfo: tasks.OpExtraInfo{
    99  			Resource: tasks.Resource{
   100  				Type: "OS::Nova::Server",
   101  				ID:   "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
   102  				Name: "ECS-0001",
   103  			},
   104  			Backup: tasks.OpExtendInfoBackup{
   105  				BackupName: "manualbk_1234",
   106  				BackupID:   "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1",
   107  			},
   108  			Common: tasks.OpExtendInfoCommon{
   109  				Progress:  100,
   110  				RequestID: "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc",
   111  			},
   112  		},
   113  		EndedAt:       "2019-05-23T14:35:23.511155",
   114  		CreatedAt:     "2019-05-23T14:31:36.039365",
   115  		OperationType: "backup",
   116  		ProjectID:     "04f1829c788037ac2fb8c01eb2b04b95",
   117  	}
   118  
   119  	expectedListResponseData = &[]tasks.OperationLog{
   120  		{
   121  			Status:       "success",
   122  			ProviderID:   "0daac4c5-6707-4851-97ba-169e36266b66",
   123  			CheckpointID: "b432511f-d889-428f-8b0e-5f47c524c6b6",
   124  			UpdatedAt:    "2019-05-23T14:35:23.584418",
   125  			ErrorInfo: tasks.OpErrorInfo{
   126  				Message: "",
   127  				Code:    "",
   128  			},
   129  			StartedAt: "2019-05-23T14:31:36.007230",
   130  			ID:        "4827f2da-b008-4507-ab7d-42d0df5ed912",
   131  			ExtraInfo: tasks.OpExtraInfo{
   132  				Resource: tasks.Resource{
   133  					Type: "OS::Nova::Server",
   134  					ID:   "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
   135  					Name: "ECS-0001",
   136  				},
   137  				Backup: tasks.OpExtendInfoBackup{
   138  					BackupName: "manualbk_1234",
   139  					BackupID:   "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1",
   140  				},
   141  				Common: tasks.OpExtendInfoCommon{
   142  					Progress:  100,
   143  					RequestID: "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc",
   144  				},
   145  			},
   146  			EndedAt:       "2019-05-23T14:35:23.511155",
   147  			CreatedAt:     "2019-05-23T14:31:36.039365",
   148  			OperationType: "backup",
   149  			ProjectID:     "04f1829c788037ac2fb8c01eb2b04b95",
   150  		},
   151  	}
   152  )
   153  
   154  func handleTaskGet(t *testing.T) {
   155  	th.Mux.HandleFunc("/operation-logs/4827f2da-b008-4507-ab7d-42d0df5ed912",
   156  		func(w http.ResponseWriter, r *http.Request) {
   157  			th.TestMethod(t, r, "GET")
   158  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   159  			w.Header().Add("Content-Type", "application/json")
   160  			w.WriteHeader(http.StatusOK)
   161  			_, _ = fmt.Fprint(w, expectedGetResponse)
   162  		})
   163  }
   164  
   165  func handleTaskList(t *testing.T) {
   166  	th.Mux.HandleFunc("/operation-logs", func(w http.ResponseWriter, r *http.Request) {
   167  		th.TestMethod(t, r, "GET")
   168  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   169  		w.Header().Add("Content-Type", "application/json")
   170  		w.WriteHeader(http.StatusOK)
   171  		_, _ = fmt.Fprint(w, expectedListResponse)
   172  	})
   173  }