github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/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/huaweicloud/golangsdk/openstack/fgs/v2/dependencies"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedListPageOneResponse = `{
    15  	"count": 4,
    16  	"dependencies": [
    17  	  {
    18  		"etag": "565a745c27a1f38d5e8af01bdab83578",
    19  		"file_name": "esdk-obs-nodejs-3.x.zip",
    20  		"id": "b1f55dc0-b3aa-4952-b5b9-883d0af27fa5",
    21  		"link": "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b1f55dc0-b3aa-4952-b5b9-883d0af27fa5.zip",
    22  		"name": "esdk-obs-nodejs-3.x",
    23  		"owner": "public",
    24  		"runtime": "Node.js6.10",
    25  		"size": 368391
    26  	  },
    27  	  {
    28  		"etag": "8d3337ba9f836cbc5014f68e3ee3b901",
    29  		"file_name": "moderation_sdk_nodejs.zip",
    30  		"id": "dabf603a-dcd7-42a8-8014-20e55c92e861",
    31  		"link": "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/dabf603a-dcd7-42a8-8014-20e55c92e861.zip",
    32  		"name": "moderation_sdk_nodejs",
    33  		"owner": "public",
    34  		"runtime": "Node.js6.10",
    35  		"size": 128876
    36  	  }
    37  	],
    38  	"next_marker": 2
    39  }`
    40  
    41  	expectedListPageTwoResponse = `{
    42  	"count": 4,
    43  	"dependencies": [
    44  	  {
    45  		"etag": "6fb79329595ef31106e01fab44e45401",
    46  		"file_name": "moment-timezone.zip",
    47  		"id": "b7022a6d-e6cd-4532-8970-313373922591",
    48  		"link": "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b7022a6d-e6cd-4532-8970-313373922591.zip",
    49  		"name": "moment-timezone",
    50  		"owner": "public",
    51  		"runtime": "Node.js6.10",
    52  		"size": 1359773
    53  	  },
    54  	  {
    55  		"etag": "2635ffb1e8198dd0dcaf6f3390a1c14f-3",
    56  		"id": "3004706f-d26a-4c87-96ae-0f1ed715ca3e",
    57  		"link": "https://testlfk.obs.cn-north-4.myhuaweicloud.com/cloud-ocr-sdk-nodejs-1.x.zip",
    58  		"name": "cloud-ocr-sdk-nodejs-1.x",
    59  		"owner": "public",
    60  		"runtime": "Node.js6.10",
    61  		"size": 21271972
    62  	  }
    63  	],
    64  	"next_marker": 4
    65  }`
    66  )
    67  
    68  var (
    69  	listOpts = dependencies.ListOpts{
    70  		Limit: "2",
    71  	}
    72  
    73  	expectedListResponseData = []dependencies.Dependency{
    74  		{
    75  			Etag:     "565a745c27a1f38d5e8af01bdab83578",
    76  			FileName: "esdk-obs-nodejs-3.x.zip",
    77  			ID:       "b1f55dc0-b3aa-4952-b5b9-883d0af27fa5",
    78  			Link:     "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b1f55dc0-b3aa-4952-b5b9-883d0af27fa5.zip",
    79  			Name:     "esdk-obs-nodejs-3.x",
    80  			Owner:    "public",
    81  			Runtime:  "Node.js6.10",
    82  			Size:     368391,
    83  		},
    84  		{
    85  			Etag:     "8d3337ba9f836cbc5014f68e3ee3b901",
    86  			FileName: "moderation_sdk_nodejs.zip",
    87  			ID:       "dabf603a-dcd7-42a8-8014-20e55c92e861",
    88  			Link:     "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/dabf603a-dcd7-42a8-8014-20e55c92e861.zip",
    89  			Name:     "moderation_sdk_nodejs",
    90  			Owner:    "public",
    91  			Runtime:  "Node.js6.10",
    92  			Size:     128876,
    93  		},
    94  		{
    95  			Etag:     "6fb79329595ef31106e01fab44e45401",
    96  			FileName: "moment-timezone.zip",
    97  			ID:       "b7022a6d-e6cd-4532-8970-313373922591",
    98  			Link:     "https://functionstorage-cn-north-4.obs.cn-north-4.myhuaweicloud.com/depends/public/b7022a6d-e6cd-4532-8970-313373922591.zip",
    99  			Name:     "moment-timezone",
   100  			Owner:    "public",
   101  			Runtime:  "Node.js6.10",
   102  			Size:     1359773,
   103  		},
   104  		{
   105  			Etag:    "2635ffb1e8198dd0dcaf6f3390a1c14f-3",
   106  			ID:      "3004706f-d26a-4c87-96ae-0f1ed715ca3e",
   107  			Link:    "https://testlfk.obs.cn-north-4.myhuaweicloud.com/cloud-ocr-sdk-nodejs-1.x.zip",
   108  			Name:    "cloud-ocr-sdk-nodejs-1.x",
   109  			Owner:   "public",
   110  			Runtime: "Node.js6.10",
   111  			Size:    21271972,
   112  		},
   113  	}
   114  )
   115  
   116  func handleV2DependenciesList(t *testing.T) {
   117  	th.Mux.HandleFunc("/fgs/dependencies", func(w http.ResponseWriter, r *http.Request) {
   118  		th.TestMethod(t, r, "GET")
   119  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   120  		th.TestHeader(t, r, "Accept", "application/json")
   121  		w.Header().Set("Content-Type", "application/json")
   122  		r.ParseForm()
   123  		marker := r.Form.Get("marker")
   124  		switch marker {
   125  		case "":
   126  			fmt.Fprintf(w, expectedListPageOneResponse)
   127  		case "2":
   128  			fmt.Fprintf(w, expectedListPageTwoResponse)
   129  		default:
   130  			t.Fatalf("Unexpected marker: [%s]", marker)
   131  		}
   132  	})
   133  }