github.com/aavshr/aws-sdk-go@v1.41.3/private/protocol/idempotency_test.go (about)

     1  package protocol_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/aavshr/aws-sdk-go/private/protocol"
     8  )
     9  
    10  func TestCanSetIdempotencyToken(t *testing.T) {
    11  	cases := []struct {
    12  		CanSet bool
    13  		Case   interface{}
    14  	}{
    15  		{
    16  			true,
    17  			struct {
    18  				Field *string `idempotencyToken:"true"`
    19  			}{},
    20  		},
    21  		{
    22  			true,
    23  			struct {
    24  				Field string `idempotencyToken:"true"`
    25  			}{},
    26  		},
    27  		{
    28  			false,
    29  			struct {
    30  				Field *string `idempotencyToken:"true"`
    31  			}{Field: new(string)},
    32  		},
    33  		{
    34  			false,
    35  			struct {
    36  				Field string `idempotencyToken:"true"`
    37  			}{Field: "value"},
    38  		},
    39  		{
    40  			false,
    41  			struct {
    42  				Field *int `idempotencyToken:"true"`
    43  			}{},
    44  		},
    45  		{
    46  			false,
    47  			struct {
    48  				Field *string
    49  			}{},
    50  		},
    51  	}
    52  
    53  	for i, c := range cases {
    54  		v := reflect.Indirect(reflect.ValueOf(c.Case))
    55  		ty := v.Type()
    56  		canSet := protocol.CanSetIdempotencyToken(v.Field(0), ty.Field(0))
    57  		if e, a := c.CanSet, canSet; e != a {
    58  			t.Errorf("%d, expect %v, got %v", i, e, a)
    59  		}
    60  	}
    61  }
    62  
    63  func TestSetIdempotencyToken(t *testing.T) {
    64  	cases := []struct {
    65  		Case interface{}
    66  	}{
    67  		{
    68  			&struct {
    69  				Field *string `idempotencyToken:"true"`
    70  			}{},
    71  		},
    72  		{
    73  			&struct {
    74  				Field string `idempotencyToken:"true"`
    75  			}{},
    76  		},
    77  		{
    78  			&struct {
    79  				Field *string `idempotencyToken:"true"`
    80  			}{Field: new(string)},
    81  		},
    82  		{
    83  			&struct {
    84  				Field string `idempotencyToken:"true"`
    85  			}{Field: ""},
    86  		},
    87  	}
    88  
    89  	for i, c := range cases {
    90  		v := reflect.Indirect(reflect.ValueOf(c.Case))
    91  
    92  		protocol.SetIdempotencyToken(v.Field(0))
    93  		if v.Field(0).Interface() == nil {
    94  			t.Errorf("%d, expect not nil", i)
    95  		}
    96  	}
    97  }
    98  
    99  func TestUUIDVersion4(t *testing.T) {
   100  	uuid := protocol.UUIDVersion4(make([]byte, 16))
   101  	if e, a := `00000000-0000-4000-8000-000000000000`, uuid; e != a {
   102  		t.Errorf("expect %v, got %v", e, a)
   103  	}
   104  
   105  	b := make([]byte, 16)
   106  	for i := 0; i < len(b); i++ {
   107  		b[i] = 1
   108  	}
   109  	uuid = protocol.UUIDVersion4(b)
   110  	if e, a := `01010101-0101-4101-8101-010101010101`, uuid; e != a {
   111  		t.Errorf("expect %v, got %v", e, a)
   112  	}
   113  }