github.com/aavshr/aws-sdk-go@v1.41.3/service/s3/s3crypto/mat_desc_test.go (about)

     1  //go:build go1.7
     2  // +build go1.7
     3  
     4  package s3crypto
     5  
     6  import (
     7  	"reflect"
     8  	"testing"
     9  
    10  	"github.com/aavshr/aws-sdk-go/aws"
    11  )
    12  
    13  func TestEncodeMaterialDescription(t *testing.T) {
    14  	md := MaterialDescription{}
    15  	md["foo"] = aws.String("bar")
    16  	b, err := md.encodeDescription()
    17  	expected := `{"foo":"bar"}`
    18  	if err != nil {
    19  		t.Errorf("expected no error, but received %v", err)
    20  	}
    21  	if expected != string(b) {
    22  		t.Errorf("expected %s, but received %s", expected, string(b))
    23  	}
    24  }
    25  func TestDecodeMaterialDescription(t *testing.T) {
    26  	md := MaterialDescription{}
    27  	json := `{"foo":"bar"}`
    28  	err := md.decodeDescription([]byte(json))
    29  	expected := MaterialDescription{
    30  		"foo": aws.String("bar"),
    31  	}
    32  	if err != nil {
    33  		t.Errorf("expected no error, but received %v", err)
    34  	}
    35  	if !reflect.DeepEqual(expected, md) {
    36  		t.Error("expected material description to be equivalent, but received otherwise")
    37  	}
    38  }
    39  
    40  func TestMaterialDescription_Clone(t *testing.T) {
    41  	tests := map[string]struct {
    42  		md        MaterialDescription
    43  		wantClone MaterialDescription
    44  	}{
    45  		"it handles nil": {
    46  			md:        nil,
    47  			wantClone: nil,
    48  		},
    49  		"it copies all values": {
    50  			md: MaterialDescription{
    51  				"key1": aws.String("value1"),
    52  				"key2": aws.String("value2"),
    53  			},
    54  			wantClone: MaterialDescription{
    55  				"key1": aws.String("value1"),
    56  				"key2": aws.String("value2"),
    57  			},
    58  		},
    59  	}
    60  	for name, tt := range tests {
    61  		t.Run(name, func(t *testing.T) {
    62  			if gotClone := tt.md.Clone(); !reflect.DeepEqual(gotClone, tt.wantClone) {
    63  				t.Errorf("Clone() = %v, want %v", gotClone, tt.wantClone)
    64  			}
    65  		})
    66  	}
    67  }