...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package storage
16
17 import (
18 "testing"
19
20 "github.com/google/go-cmp/cmp"
21 "google.golang.org/api/option"
22 )
23
24 func TestApplyStorageOpt(t *testing.T) {
25 for _, test := range []struct {
26 desc string
27 opts []option.ClientOption
28 want storageConfig
29 }{
30 {
31 desc: "set JSON option",
32 opts: []option.ClientOption{WithJSONReads()},
33 want: storageConfig{
34 useJSONforReads: true,
35 readAPIWasSet: true,
36 },
37 },
38 {
39 desc: "set XML option",
40 opts: []option.ClientOption{WithXMLReads()},
41 want: storageConfig{
42 useJSONforReads: false,
43 readAPIWasSet: true,
44 },
45 },
46 {
47 desc: "set conflicting options, last option set takes precedence",
48 opts: []option.ClientOption{WithJSONReads(), WithXMLReads()},
49 want: storageConfig{
50 useJSONforReads: false,
51 readAPIWasSet: true,
52 },
53 },
54 {
55 desc: "empty options",
56 opts: []option.ClientOption{},
57 want: storageConfig{
58 useJSONforReads: false,
59 readAPIWasSet: false,
60 },
61 },
62 {
63 desc: "set Google API option",
64 opts: []option.ClientOption{option.WithEndpoint("")},
65 want: storageConfig{
66 useJSONforReads: false,
67 readAPIWasSet: false,
68 },
69 },
70 } {
71 t.Run(test.desc, func(t *testing.T) {
72 var got storageConfig
73 for _, opt := range test.opts {
74 if storageOpt, ok := opt.(storageClientOption); ok {
75 storageOpt.ApplyStorageOpt(&got)
76 }
77 }
78 if !cmp.Equal(got, test.want, cmp.AllowUnexported(storageConfig{})) {
79 t.Errorf(cmp.Diff(got, test.want, cmp.AllowUnexported(storageConfig{})))
80 }
81 })
82 }
83 }
84
View as plain text