github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/fgs/v2/dependencies/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/chnsz/golangsdk/openstack/fgs/v2/dependencies"
     9  	th "github.com/chnsz/golangsdk/testhelper"
    10  	"github.com/chnsz/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedGetResponse = `{
    15  	"description": "Created by terraform script",
    16  	"etag": "80d6b982fc54b77202b914b559342b11",
    17  	"id": "e6cc2ebe-0bae-4b69-a1d6-8198bc356ff8",
    18  	"link": "https://script-fgs-dependencies-bucket.obs.cn-north-4.myhuaweicloud.com/terraform_dependencies/huaweicloudsdkcore.zip",
    19  	"name": "script_fgs_dependencies_dependency",
    20  	"owner": "abc",
    21  	"runtime": "Python3.6",
    22  	"size": 1281293
    23  }`
    24  
    25  	expectedListPageOneResponse = `{
    26  	"count": 4,
    27  	"dependencies": [
    28  	  {
    29  		"etag": "565a745c27a1f38d5e8af01bdab83578",
    30  		"file_name": "esdk-obs-nodejs-3.x.zip",
    31  		"id": "b1f55dc0-b3aa-4952-b5b9-883d0af27fa5",
    32  		"link": "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b1f55dc0-b3aa-4952-b5b9-883d0af27fa5.zip",
    33  		"name": "esdk-obs-nodejs-3.x",
    34  		"owner": "public",
    35  		"runtime": "Node.js6.10",
    36  		"size": 368391
    37  	  },
    38  	  {
    39  		"etag": "8d3337ba9f836cbc5014f68e3ee3b901",
    40  		"file_name": "moderation_sdk_nodejs.zip",
    41  		"id": "dabf603a-dcd7-42a8-8014-20e55c92e861",
    42  		"link": "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/dabf603a-dcd7-42a8-8014-20e55c92e861.zip",
    43  		"name": "moderation_sdk_nodejs",
    44  		"owner": "public",
    45  		"runtime": "Node.js6.10",
    46  		"size": 128876
    47  	  }
    48  	],
    49  	"next_marker": 2
    50  }`
    51  
    52  	expectedListPageTwoResponse = `{
    53  	"count": 4,
    54  	"dependencies": [
    55  	  {
    56  		"etag": "6fb79329595ef31106e01fab44e45401",
    57  		"file_name": "moment-timezone.zip",
    58  		"id": "b7022a6d-e6cd-4532-8970-313373922591",
    59  		"link": "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b7022a6d-e6cd-4532-8970-313373922591.zip",
    60  		"name": "moment-timezone",
    61  		"owner": "public",
    62  		"runtime": "Node.js6.10",
    63  		"size": 1359773
    64  	  },
    65  	  {
    66  		"etag": "2635ffb1e8198dd0dcaf6f3390a1c14f-3",
    67  		"id": "3004706f-d26a-4c87-96ae-0f1ed715ca3e",
    68  		"link": "https://testlfk.obs.cn-north-4.myhuaweicloud.com/cloud-ocr-sdk-nodejs-1.x.zip",
    69  		"name": "cloud-ocr-sdk-nodejs-1.x",
    70  		"owner": "public",
    71  		"runtime": "Node.js6.10",
    72  		"size": 21271972
    73  	  }
    74  	],
    75  	"next_marker": 4
    76  }`
    77  )
    78  
    79  var (
    80  	desc       = "Created by terraform script"
    81  	createOpts = dependencies.DependOpts{
    82  		Name:        "custom_terraform_sdk_core",
    83  		Description: &desc,
    84  		Type:        "obs",
    85  		Link:        "https://script-fgs-dependencies-bucket.obs.cn-north-4.myhuaweicloud.com/terraform_dependencies/huaweicloudsdkcore.zip",
    86  		Runtime:     "Python3.6",
    87  	}
    88  
    89  	listOpts = dependencies.ListOpts{
    90  		Limit: "2",
    91  	}
    92  
    93  	expectedGetResponseData = dependencies.Dependency{
    94  		Description: "Created by terraform script",
    95  		Etag:        "80d6b982fc54b77202b914b559342b11",
    96  		ID:          "e6cc2ebe-0bae-4b69-a1d6-8198bc356ff8",
    97  		Link:        "https://script-fgs-dependencies-bucket.obs.cn-north-4.myhuaweicloud.com/terraform_dependencies/huaweicloudsdkcore.zip",
    98  		Name:        "script_fgs_dependencies_dependency",
    99  		Owner:       "abc",
   100  		Runtime:     "Python3.6",
   101  		Size:        1281293,
   102  	}
   103  
   104  	expectedListResponseData = []dependencies.Dependency{
   105  		{
   106  			Etag:     "565a745c27a1f38d5e8af01bdab83578",
   107  			FileName: "esdk-obs-nodejs-3.x.zip",
   108  			ID:       "b1f55dc0-b3aa-4952-b5b9-883d0af27fa5",
   109  			Link:     "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b1f55dc0-b3aa-4952-b5b9-883d0af27fa5.zip",
   110  			Name:     "esdk-obs-nodejs-3.x",
   111  			Owner:    "public",
   112  			Runtime:  "Node.js6.10",
   113  			Size:     368391,
   114  		},
   115  		{
   116  			Etag:     "8d3337ba9f836cbc5014f68e3ee3b901",
   117  			FileName: "moderation_sdk_nodejs.zip",
   118  			ID:       "dabf603a-dcd7-42a8-8014-20e55c92e861",
   119  			Link:     "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/dabf603a-dcd7-42a8-8014-20e55c92e861.zip",
   120  			Name:     "moderation_sdk_nodejs",
   121  			Owner:    "public",
   122  			Runtime:  "Node.js6.10",
   123  			Size:     128876,
   124  		},
   125  		{
   126  			Etag:     "6fb79329595ef31106e01fab44e45401",
   127  			FileName: "moment-timezone.zip",
   128  			ID:       "b7022a6d-e6cd-4532-8970-313373922591",
   129  			Link:     "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b7022a6d-e6cd-4532-8970-313373922591.zip",
   130  			Name:     "moment-timezone",
   131  			Owner:    "public",
   132  			Runtime:  "Node.js6.10",
   133  			Size:     1359773,
   134  		},
   135  		{
   136  			Etag:    "2635ffb1e8198dd0dcaf6f3390a1c14f-3",
   137  			ID:      "3004706f-d26a-4c87-96ae-0f1ed715ca3e",
   138  			Link:    "https://testlfk.obs.cn-north-4.myhuaweicloud.com/cloud-ocr-sdk-nodejs-1.x.zip",
   139  			Name:    "cloud-ocr-sdk-nodejs-1.x",
   140  			Owner:   "public",
   141  			Runtime: "Node.js6.10",
   142  			Size:    21271972,
   143  		},
   144  	}
   145  )
   146  
   147  func handleV2DependencyCreate(t *testing.T) {
   148  	th.Mux.HandleFunc("/fgs/dependencies",
   149  		func(w http.ResponseWriter, r *http.Request) {
   150  			th.TestMethod(t, r, "POST")
   151  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   152  			w.Header().Add("Content-Type", "application/json")
   153  			w.WriteHeader(http.StatusOK)
   154  			_, _ = fmt.Fprint(w, expectedGetResponse)
   155  		})
   156  }
   157  
   158  func handleV2DependencyGet(t *testing.T) {
   159  	th.Mux.HandleFunc("/fgs/dependencies/e6cc2ebe-0bae-4b69-a1d6-8198bc356ff8",
   160  		func(w http.ResponseWriter, r *http.Request) {
   161  			th.TestMethod(t, r, "GET")
   162  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   163  			w.Header().Add("Content-Type", "application/json")
   164  			w.WriteHeader(http.StatusOK)
   165  			_, _ = fmt.Fprint(w, expectedGetResponse)
   166  		})
   167  }
   168  
   169  func handleV2DependenciesList(t *testing.T) {
   170  	th.Mux.HandleFunc("/fgs/dependencies", func(w http.ResponseWriter, r *http.Request) {
   171  		th.TestMethod(t, r, "GET")
   172  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   173  		th.TestHeader(t, r, "Accept", "application/json")
   174  		w.Header().Set("Content-Type", "application/json")
   175  		r.ParseForm()
   176  		marker := r.Form.Get("marker")
   177  		switch marker {
   178  		case "":
   179  			fmt.Fprintf(w, expectedListPageOneResponse)
   180  		case "2":
   181  			fmt.Fprintf(w, expectedListPageTwoResponse)
   182  		default:
   183  			t.Fatalf("Unexpected marker: [%s]", marker)
   184  		}
   185  	})
   186  }
   187  
   188  func handleV2DependencyUpdate(t *testing.T) {
   189  	th.Mux.HandleFunc("/fgs/dependencies/e6cc2ebe-0bae-4b69-a1d6-8198bc356ff8",
   190  		func(w http.ResponseWriter, r *http.Request) {
   191  			th.TestMethod(t, r, "PUT")
   192  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   193  			w.Header().Add("Content-Type", "application/json")
   194  			w.WriteHeader(http.StatusOK)
   195  			_, _ = fmt.Fprint(w, expectedGetResponse)
   196  		})
   197  }
   198  
   199  func handleV2DependencyDelete(t *testing.T) {
   200  	th.Mux.HandleFunc("/fgs/dependencies/e6cc2ebe-0bae-4b69-a1d6-8198bc356ff8",
   201  		func(w http.ResponseWriter, r *http.Request) {
   202  			th.TestMethod(t, r, "DELETE")
   203  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   204  			w.Header().Add("Content-Type", "application/json")
   205  			w.WriteHeader(http.StatusNoContent)
   206  		})
   207  }