2021-05-13 10:55:33 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 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 main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArgsParse(t *testing.T) {
|
|
|
|
Convey("When parsing command line arguments", t, func() {
|
|
|
|
flags := flag.NewFlagSet(ProgramName, flag.ExitOnError)
|
|
|
|
|
2021-11-25 10:14:19 +00:00
|
|
|
Convey("When -no-publish and -oneshot flags are passed", func() {
|
2022-11-07 11:58:40 +00:00
|
|
|
args, finderArgs := parseArgs(flags, "-oneshot", "-no-publish", "-kubelet-config-uri=https://%s:%d/configz")
|
2021-05-13 10:55:33 +00:00
|
|
|
|
|
|
|
Convey("noPublish is set and args.sources is set to the default value", func() {
|
|
|
|
So(args.NoPublish, ShouldBeTrue)
|
|
|
|
So(args.Oneshot, ShouldBeTrue)
|
2022-11-02 14:01:25 +00:00
|
|
|
So(args.ConfigFile, ShouldEqual, "/etc/kubernetes/node-feature-discovery/nfd-topology-updater.conf")
|
2021-05-13 10:55:33 +00:00
|
|
|
So(finderArgs.SleepInterval, ShouldEqual, 60*time.Second)
|
|
|
|
So(finderArgs.PodResourceSocketPath, ShouldEqual, "/var/lib/kubelet/pod-resources/kubelet.sock")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-11-02 14:01:25 +00:00
|
|
|
Convey("When valid args are specified for -kubelet-config-url, -sleep-interval and -config,", func() {
|
2021-05-13 10:55:33 +00:00
|
|
|
args, finderArgs := parseArgs(flags,
|
2022-11-07 11:58:40 +00:00
|
|
|
"-kubelet-config-uri=file:///path/testconfig.yaml",
|
2022-11-02 14:01:25 +00:00
|
|
|
"-sleep-interval=30s",
|
|
|
|
"-config=/path/nfd-topology-updater.conf")
|
2021-05-13 10:55:33 +00:00
|
|
|
|
|
|
|
Convey("args.sources is set to appropriate values", func() {
|
|
|
|
So(args.NoPublish, ShouldBeFalse)
|
|
|
|
So(args.Oneshot, ShouldBeFalse)
|
2022-11-02 14:01:25 +00:00
|
|
|
So(args.ConfigFile, ShouldEqual, "/path/nfd-topology-updater.conf")
|
2021-05-13 10:55:33 +00:00
|
|
|
So(finderArgs.SleepInterval, ShouldEqual, 30*time.Second)
|
2022-11-07 11:58:40 +00:00
|
|
|
So(finderArgs.KubeletConfigURI, ShouldEqual, "file:///path/testconfig.yaml")
|
2021-05-13 10:55:33 +00:00
|
|
|
So(finderArgs.PodResourceSocketPath, ShouldEqual, "/var/lib/kubelet/pod-resources/kubelet.sock")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-11-25 10:14:19 +00:00
|
|
|
Convey("When valid args are specified for -podresources-socket flag and -sleep-interval is specified", func() {
|
2021-05-13 10:55:33 +00:00
|
|
|
args, finderArgs := parseArgs(flags,
|
2022-11-07 11:58:40 +00:00
|
|
|
"-kubelet-config-uri=https://%s:%d/configz",
|
2021-11-25 10:14:19 +00:00
|
|
|
"-podresources-socket=/path/testkubelet.sock",
|
|
|
|
"-sleep-interval=30s")
|
2021-05-13 10:55:33 +00:00
|
|
|
|
|
|
|
Convey("args.sources is set to appropriate values", func() {
|
|
|
|
So(args.NoPublish, ShouldBeFalse)
|
|
|
|
So(args.Oneshot, ShouldBeFalse)
|
|
|
|
So(finderArgs.SleepInterval, ShouldEqual, 30*time.Second)
|
|
|
|
So(finderArgs.PodResourceSocketPath, ShouldEqual, "/path/testkubelet.sock")
|
|
|
|
})
|
|
|
|
})
|
2021-11-25 10:14:19 +00:00
|
|
|
Convey("When valid -sleep-inteval is specified", func() {
|
2021-05-13 10:55:33 +00:00
|
|
|
args, finderArgs := parseArgs(flags,
|
2022-11-07 11:58:40 +00:00
|
|
|
"-kubelet-config-uri=https://%s:%d/configz",
|
2021-11-25 10:14:19 +00:00
|
|
|
"-sleep-interval=30s")
|
2021-05-13 10:55:33 +00:00
|
|
|
|
|
|
|
Convey("args.sources is set to appropriate values", func() {
|
|
|
|
So(args.NoPublish, ShouldBeFalse)
|
|
|
|
So(args.Oneshot, ShouldBeFalse)
|
|
|
|
So(finderArgs.SleepInterval, ShouldEqual, 30*time.Second)
|
|
|
|
So(finderArgs.PodResourceSocketPath, ShouldEqual, "/var/lib/kubelet/pod-resources/kubelet.sock")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("When All valid args are specified", func() {
|
|
|
|
args, finderArgs := parseArgs(flags,
|
2021-11-25 10:14:19 +00:00
|
|
|
"-no-publish",
|
|
|
|
"-sleep-interval=30s",
|
2022-11-07 11:58:40 +00:00
|
|
|
"-kubelet-config-uri=file:///path/testconfig.yaml",
|
2022-12-02 09:47:56 +00:00
|
|
|
"-podresources-socket=/path/testkubelet.sock")
|
2021-11-25 10:14:19 +00:00
|
|
|
|
|
|
|
Convey("-no-publish is set and args.sources is set to appropriate values", func() {
|
2021-05-13 10:55:33 +00:00
|
|
|
So(args.NoPublish, ShouldBeTrue)
|
|
|
|
So(finderArgs.SleepInterval, ShouldEqual, 30*time.Second)
|
2022-11-07 11:58:40 +00:00
|
|
|
So(finderArgs.KubeletConfigURI, ShouldEqual, "file:///path/testconfig.yaml")
|
2021-05-13 10:55:33 +00:00
|
|
|
So(finderArgs.PodResourceSocketPath, ShouldEqual, "/path/testkubelet.sock")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|