...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package storage
16
17 import (
18 "reflect"
19 "testing"
20 "time"
21
22 "github.com/google/go-cmp/cmp"
23 )
24
25 func TestPostPolicyV4OptionsClone(t *testing.T) {
26 t.Parallel()
27
28 opts := &PostPolicyV4Options{
29 GoogleAccessID: "accessID",
30 PrivateKey: []byte{},
31 SignBytes: func(b []byte) ([]byte, error) {
32 return b, nil
33 },
34 SignRawBytes: func(bytes []byte) ([]byte, error) {
35 return bytes, nil
36 },
37 Expires: time.Now(),
38 Style: VirtualHostedStyle(),
39 Insecure: true,
40 Fields: &PolicyV4Fields{ACL: "test-acl"},
41 Conditions: []PostPolicyV4Condition{},
42 shouldHashSignBytes: true,
43 Hostname: "localhost:9000",
44 }
45
46
47
48 reflectOpts := reflect.ValueOf(*opts)
49 for i := 0; i < reflectOpts.NumField(); i++ {
50 zero, err := isZeroValue(reflectOpts.Field(i))
51 if err != nil {
52 t.Errorf("IsZero: %v", err)
53 }
54 if zero {
55 t.Errorf("PostPolicyV4Options field %d not set", i)
56 }
57 }
58
59
60 optsClone := opts.clone()
61
62
63 signBytesComp := func(a func([]byte) ([]byte, error), b func([]byte) ([]byte, error)) bool {
64 return reflect.ValueOf(a) == reflect.ValueOf(b)
65 }
66
67 if diff := cmp.Diff(opts, optsClone, cmp.Comparer(signBytesComp),
68 cmp.AllowUnexported(PostPolicyV4Options{})); diff != "" {
69 t.Errorf("clone does not match (original: -, cloned: +):\n%s", diff)
70 }
71 }
72
View as plain text