2019-01-23 10:15:47 +02:00
|
|
|
/*
|
|
|
|
Copyright 2019 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.
|
|
|
|
*/
|
|
|
|
|
2016-07-28 18:00:42 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-04-11 19:33:06 +03:00
|
|
|
"time"
|
2016-07-28 18:00:42 -07:00
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
2016-12-16 15:50:48 -08:00
|
|
|
func TestArgsParse(t *testing.T) {
|
|
|
|
Convey("When parsing command line arguments", t, func() {
|
2018-04-11 19:33:06 +03:00
|
|
|
Convey("When --no-publish and --oneshot flags are passed", func() {
|
2019-01-23 10:15:47 +02:00
|
|
|
args, err := argsParse([]string{"--no-publish", "--oneshot"})
|
2016-12-16 15:50:48 -08:00
|
|
|
|
2018-04-11 19:33:06 +03:00
|
|
|
Convey("noPublish is set and args.sources is set to the default value", func() {
|
2020-12-01 14:27:47 +02:00
|
|
|
So(args.SleepInterval, ShouldEqual, nil)
|
2020-11-27 10:19:31 +02:00
|
|
|
So(*args.NoPublish, ShouldBeTrue)
|
2019-02-08 21:43:54 +02:00
|
|
|
So(args.Oneshot, ShouldBeTrue)
|
2020-12-01 15:53:04 +02:00
|
|
|
So(args.Sources, ShouldBeNil)
|
2020-12-01 14:54:59 +02:00
|
|
|
So(args.LabelWhiteList, ShouldBeNil)
|
2019-01-23 10:15:47 +02:00
|
|
|
So(err, ShouldBeNil)
|
2016-12-16 15:50:48 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-04-11 19:33:06 +03:00
|
|
|
Convey("When --sources flag is passed and set to some values, --sleep-inteval is specified", func() {
|
2019-01-23 10:15:47 +02:00
|
|
|
args, err := argsParse([]string{"--sources=fake1,fake2,fake3", "--sleep-interval=30s"})
|
2016-12-16 15:50:48 -08:00
|
|
|
|
2018-04-11 19:33:06 +03:00
|
|
|
Convey("args.sources is set to appropriate values", func() {
|
2020-12-01 14:27:47 +02:00
|
|
|
So(*args.SleepInterval, ShouldEqual, 30*time.Second)
|
2020-11-27 10:19:31 +02:00
|
|
|
So(args.NoPublish, ShouldBeNil)
|
2019-02-08 21:43:54 +02:00
|
|
|
So(args.Oneshot, ShouldBeFalse)
|
2020-12-01 15:53:04 +02:00
|
|
|
So(*args.Sources, ShouldResemble, []string{"fake1", "fake2", "fake3"})
|
2020-12-01 14:54:59 +02:00
|
|
|
So(args.LabelWhiteList, ShouldBeNil)
|
2019-01-23 10:15:47 +02:00
|
|
|
So(err, ShouldBeNil)
|
2016-12-16 15:50:48 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("When --label-whitelist flag is passed and set to some value", func() {
|
2019-01-23 10:15:47 +02:00
|
|
|
args, err := argsParse([]string{"--label-whitelist=.*rdt.*"})
|
2016-12-16 15:50:48 -08:00
|
|
|
|
2018-04-11 19:33:06 +03:00
|
|
|
Convey("args.labelWhiteList is set to appropriate value and args.sources is set to default value", func() {
|
2020-11-27 10:19:31 +02:00
|
|
|
So(args.NoPublish, ShouldBeNil)
|
2020-12-01 15:53:04 +02:00
|
|
|
So(args.Sources, ShouldBeNil)
|
2020-12-01 14:54:59 +02:00
|
|
|
So(args.LabelWhiteList.String(), ShouldResemble, ".*rdt.*")
|
2019-01-23 10:15:47 +02:00
|
|
|
So(err, ShouldBeNil)
|
2016-12-16 15:50:48 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-01-29 16:21:48 +02:00
|
|
|
Convey("When valid args are specified", func() {
|
2019-01-30 14:54:51 +02:00
|
|
|
args, err := argsParse([]string{"--no-publish", "--sources=fake1,fake2,fake3", "--ca-file=ca", "--cert-file=crt", "--key-file=key"})
|
2016-12-16 15:50:48 -08:00
|
|
|
|
2018-04-11 19:33:06 +03:00
|
|
|
Convey("--no-publish is set and args.sources is set to appropriate values", func() {
|
2020-11-27 10:19:31 +02:00
|
|
|
So(*args.NoPublish, ShouldBeTrue)
|
2019-02-08 21:43:54 +02:00
|
|
|
So(args.CaFile, ShouldEqual, "ca")
|
|
|
|
So(args.CertFile, ShouldEqual, "crt")
|
|
|
|
So(args.KeyFile, ShouldEqual, "key")
|
2020-12-01 15:53:04 +02:00
|
|
|
So(*args.Sources, ShouldResemble, []string{"fake1", "fake2", "fake3"})
|
2020-12-01 14:54:59 +02:00
|
|
|
So(args.LabelWhiteList, ShouldBeNil)
|
2016-12-16 15:50:48 -08:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
2019-01-23 10:15:47 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|