forked from kubernetes-sigs/aws-ebs-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_test.go
143 lines (125 loc) · 4.63 KB
/
driver_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package driver
import (
"reflect"
"testing"
"time"
)
func TestWithEndpoint(t *testing.T) {
value := "endpoint"
options := &DriverOptions{}
WithEndpoint(value)(options)
if options.endpoint != value {
t.Fatalf("expected endpoint option got set to %q but is set to %q", value, options.endpoint)
}
}
func TestWithExtraTags(t *testing.T) {
value := map[string]string{"foo": "bar"}
options := &DriverOptions{}
WithExtraTags(value)(options)
if !reflect.DeepEqual(options.extraTags, value) {
t.Fatalf("expected extraTags option got set to %+v but is set to %+v", value, options.extraTags)
}
}
func TestWithExtraVolumeTags(t *testing.T) {
value := map[string]string{"foo": "bar"}
options := &DriverOptions{}
WithExtraVolumeTags(value)(options)
if !reflect.DeepEqual(options.extraTags, value) {
t.Fatalf("expected extraTags option got set to %+v but is set to %+v", value, options.extraTags)
}
}
func TestWithExtraVolumeTagsNoOverwrite(t *testing.T) {
extraTagsValue := map[string]string{"foo": "bar"}
options := &DriverOptions{}
WithExtraTags(extraTagsValue)(options)
extraVolumeTagsValue := map[string]string{"baz": "qux"}
WithExtraVolumeTags(extraVolumeTagsValue)(options)
if !reflect.DeepEqual(options.extraTags, extraTagsValue) {
t.Fatalf("expected extraTags option got set to %+v but is set to %+v", extraTagsValue, options.extraTags)
}
}
func TestWithMode(t *testing.T) {
value := Mode("mode")
options := &DriverOptions{}
WithMode(value)(options)
if options.mode != value {
t.Fatalf("expected mode option got set to %q but is set to %q", value, options.mode)
}
}
func TestWithVolumeAttachLimit(t *testing.T) {
var value int64 = 42
options := &DriverOptions{}
WithVolumeAttachLimit(value)(options)
if options.volumeAttachLimit != value {
t.Fatalf("expected volumeAttachLimit option got set to %d but is set to %d", value, options.volumeAttachLimit)
}
}
func TestWithVolumeAttachLimitFromMetadata(t *testing.T) {
value := 10
options := &DriverOptions{}
WithReservedVolumeAttachments(value)(options)
if options.reservedVolumeAttachments != value {
t.Fatalf("expected reservedVolumeAttachments option got set to %d but is set to %d", value, options.reservedVolumeAttachments)
}
}
func TestWithClusterID(t *testing.T) {
var id string = "test-cluster-id"
options := &DriverOptions{}
WithKubernetesClusterID(id)(options)
if options.kubernetesClusterID != id {
t.Fatalf("expected kubernetesClusterID option got set to %s but is set to %s", id, options.kubernetesClusterID)
}
}
func TestWithAwsSdkDebugLog(t *testing.T) {
var enableSdkDebugLog bool = true
options := &DriverOptions{}
WithAwsSdkDebugLog(enableSdkDebugLog)(options)
if options.awsSdkDebugLog != enableSdkDebugLog {
t.Fatalf("expected awsSdkDebugLog option got set to %v but is set to %v", enableSdkDebugLog, options.awsSdkDebugLog)
}
}
func TestWithUserAgentExtra(t *testing.T) {
var userAgentExtra string = "test-user-agent"
options := &DriverOptions{}
WithUserAgentExtra(userAgentExtra)(options)
if options.userAgentExtra != userAgentExtra {
t.Fatalf("expected userAgentExtra option got set to %s but is set to %s", userAgentExtra, options.userAgentExtra)
}
}
func TestWithOtelTracing(t *testing.T) {
var enableOtelTracing bool = true
options := &DriverOptions{}
WithOtelTracing(enableOtelTracing)(options)
if options.otelTracing != enableOtelTracing {
t.Fatalf("expected otelTracing option got set to %v but is set to %v", enableOtelTracing, options.otelTracing)
}
}
func TestWithBatching(t *testing.T) {
var batching bool = true
options := &DriverOptions{}
WithBatching(batching)(options)
if options.batching != batching {
t.Fatalf("expected batching option got set to %v but is set to %v", batching, options.batching)
}
}
func TestWithModifyVolumeRequestHandlerTimeout(t *testing.T) {
timeout := 15 * time.Second
options := &DriverOptions{}
WithModifyVolumeRequestHandlerTimeout(timeout)(options)
if options.modifyVolumeRequestHandlerTimeout != timeout {
t.Fatalf("expected modifyVolumeRequestHandlerTimeout option got set to %v but is set to %v",
timeout, options.modifyVolumeRequestHandlerTimeout)
}
}