@@ -17,11 +17,15 @@ limitations under the License.
17
17
package flags
18
18
19
19
import (
20
+ "flag"
20
21
"testing"
21
22
22
23
"k8s.io/autoscaler/cluster-autoscaler/config"
23
24
kubelet_config "k8s.io/kubernetes/pkg/kubelet/apis/config"
24
25
26
+ "github.com/google/go-cmp/cmp"
27
+ "github.com/google/go-cmp/cmp/cmpopts"
28
+ "github.com/spf13/pflag"
25
29
"github.com/stretchr/testify/assert"
26
30
)
27
31
@@ -146,3 +150,47 @@ func TestParseShutdownGracePeriodsAndPriorities(t *testing.T) {
146
150
})
147
151
}
148
152
}
153
+
154
+ func TestCreateAutoscalingOptions (t * testing.T ) {
155
+ for _ , tc := range []struct {
156
+ testName string
157
+ flags []string
158
+ wantOptionsAsserter func (t * testing.T , gotOptions config.AutoscalingOptions )
159
+ }{
160
+ {
161
+ testName : "DrainPriorityConfig defaults to an empty list when the flag isn't passed" ,
162
+ flags : []string {},
163
+ wantOptionsAsserter : func (t * testing.T , gotOptions config.AutoscalingOptions ) {
164
+ if diff := cmp .Diff ([]kubelet_config.ShutdownGracePeriodByPodPriority {}, gotOptions .DrainPriorityConfig , cmpopts .EquateEmpty ()); diff != "" {
165
+ t .Errorf ("createAutoscalingOptions(): unexpected DrainPriorityConfig field (-want +got): %s" , diff )
166
+ }
167
+ },
168
+ },
169
+ {
170
+ testName : "DrainPriorityConfig is parsed correctly when the flag passed" ,
171
+ flags : []string {"--drain-priority-config" , "5000:60,3000:50,0:40" },
172
+ wantOptionsAsserter : func (t * testing.T , gotOptions config.AutoscalingOptions ) {
173
+ wantConfig := []kubelet_config.ShutdownGracePeriodByPodPriority {
174
+ {Priority : 5000 , ShutdownGracePeriodSeconds : 60 },
175
+ {Priority : 3000 , ShutdownGracePeriodSeconds : 50 },
176
+ {Priority : 0 , ShutdownGracePeriodSeconds : 40 },
177
+ }
178
+ if diff := cmp .Diff (wantConfig , gotOptions .DrainPriorityConfig ); diff != "" {
179
+ t .Errorf ("createAutoscalingOptions(): unexpected DrainPriorityConfig field (-want +got): %s" , diff )
180
+ }
181
+ },
182
+ },
183
+ } {
184
+ t .Run (tc .testName , func (t * testing.T ) {
185
+ pflag .CommandLine = pflag .NewFlagSet ("test" , pflag .ExitOnError )
186
+ pflag .CommandLine .AddGoFlagSet (flag .CommandLine )
187
+ err := pflag .CommandLine .Parse (tc .flags )
188
+ if err != nil {
189
+ t .Errorf ("pflag.CommandLine.Parse() got unexpected error: %v" , err )
190
+ }
191
+
192
+ gotOptions := createAutoscalingOptions ()
193
+ tc .wantOptionsAsserter (t , gotOptions )
194
+ })
195
+ }
196
+ }
0 commit comments