File: mat_desc_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.44.133-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 245,296 kB
  • sloc: makefile: 120
file content (67 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build go1.7
// +build go1.7

package s3crypto

import (
	"reflect"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
)

func TestEncodeMaterialDescription(t *testing.T) {
	md := MaterialDescription{}
	md["foo"] = aws.String("bar")
	b, err := md.encodeDescription()
	expected := `{"foo":"bar"}`
	if err != nil {
		t.Errorf("expected no error, but received %v", err)
	}
	if expected != string(b) {
		t.Errorf("expected %s, but received %s", expected, string(b))
	}
}
func TestDecodeMaterialDescription(t *testing.T) {
	md := MaterialDescription{}
	json := `{"foo":"bar"}`
	err := md.decodeDescription([]byte(json))
	expected := MaterialDescription{
		"foo": aws.String("bar"),
	}
	if err != nil {
		t.Errorf("expected no error, but received %v", err)
	}
	if !reflect.DeepEqual(expected, md) {
		t.Error("expected material description to be equivalent, but received otherwise")
	}
}

func TestMaterialDescription_Clone(t *testing.T) {
	tests := map[string]struct {
		md        MaterialDescription
		wantClone MaterialDescription
	}{
		"it handles nil": {
			md:        nil,
			wantClone: nil,
		},
		"it copies all values": {
			md: MaterialDescription{
				"key1": aws.String("value1"),
				"key2": aws.String("value2"),
			},
			wantClone: MaterialDescription{
				"key1": aws.String("value1"),
				"key2": aws.String("value2"),
			},
		},
	}
	for name, tt := range tests {
		t.Run(name, func(t *testing.T) {
			if gotClone := tt.md.Clone(); !reflect.DeepEqual(gotClone, tt.wantClone) {
				t.Errorf("Clone() = %v, want %v", gotClone, tt.wantClone)
			}
		})
	}
}