yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/ucloud/client_test.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ucloud
    16  
    17  import (
    18  	"testing"
    19  
    20  	"yunion.io/x/jsonutils"
    21  )
    22  
    23  func TestGetSignature(t *testing.T) {
    24  	type args struct {
    25  		params     SParams
    26  		privateKey string
    27  	}
    28  
    29  	_obj, _ := jsonutils.ParseString(`{
    30      "Password"   :  "VUNsb3VkLmNu",
    31      "Region"     :  "cn-bj2",
    32      "Zone"       :  "cn-bj2-04",
    33      "ImageId"    :  "f43736e1-65a5-4bea-ad2e-8a46e18883c2", 
    34      "CPU"        :  2,
    35      "Memory"     :  2048,
    36      "DiskSpace"  :  10,
    37      "LoginMode"  :  "Password",
    38      "Action"     :  "CreateUHostInstance",
    39      "Name"       :  "Host01",
    40      "ChargeType" :  "Month",
    41      "Quantity"   :  1,
    42      "PublicKey"  :  "ucloudsomeone@example.com1296235120854146120"
    43  }`)
    44  
    45  	obj := _obj.(*jsonutils.JSONDict)
    46  
    47  	tests := []struct {
    48  		name string
    49  		args args
    50  		want string
    51  	}{
    52  		{
    53  			name: "Ucloud api signature validate",
    54  			args: args{
    55  				params:     SParams{data: *obj},
    56  				privateKey: "46f09bb9fab4f12dfc160dae12273d5332b5debe",
    57  			},
    58  			want: "4f9ef5df2abab2c6fccd1e9515cb7e2df8c6bb65",
    59  		},
    60  	}
    61  	for _, tt := range tests {
    62  		t.Run(tt.name, func(t *testing.T) {
    63  			if got := GetSignature(tt.args.params, tt.args.privateKey); got != tt.want {
    64  				t.Errorf("GetSignature() = %v, want %v", got, tt.want)
    65  			}
    66  		})
    67  	}
    68  }