|
@@ -11,18 +11,22 @@ import (
|
|
|
"gotest.tools/fs"
|
|
|
)
|
|
|
|
|
|
-func defaultOptions(configFile string) *daemonOptions {
|
|
|
+func defaultOptions(t *testing.T, configFile string) *daemonOptions {
|
|
|
opts := newDaemonOptions(&config.Config{})
|
|
|
opts.flags = &pflag.FlagSet{}
|
|
|
opts.InstallFlags(opts.flags)
|
|
|
- installConfigFlags(opts.daemonConfig, opts.flags)
|
|
|
+ if err := installConfigFlags(opts.daemonConfig, opts.flags); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ defaultDaemonConfigFile, err := getDefaultDaemonConfigFile()
|
|
|
+ assert.NilError(t, err)
|
|
|
opts.flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "")
|
|
|
opts.configFile = configFile
|
|
|
return opts
|
|
|
}
|
|
|
|
|
|
func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
|
|
|
- opts := defaultOptions("")
|
|
|
+ opts := defaultOptions(t, "")
|
|
|
opts.Debug = true
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
@@ -34,7 +38,7 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
|
|
|
- opts := defaultOptions("")
|
|
|
+ opts := defaultOptions(t, "")
|
|
|
opts.TLSOptions.CAFile = "/tmp/ca.pem"
|
|
|
opts.TLS = true
|
|
|
|
|
@@ -49,7 +53,7 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
|
|
|
defer tempFile.Remove()
|
|
|
configFile := tempFile.Path()
|
|
|
|
|
|
- opts := defaultOptions(configFile)
|
|
|
+ opts := defaultOptions(t, configFile)
|
|
|
flags := opts.flags
|
|
|
|
|
|
assert.Check(t, flags.Set("config-file", configFile))
|
|
@@ -65,7 +69,7 @@ func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) {
|
|
|
defer tempFile.Remove()
|
|
|
configFile := tempFile.Path()
|
|
|
|
|
|
- opts := defaultOptions(configFile)
|
|
|
+ opts := defaultOptions(t, configFile)
|
|
|
flags := opts.flags
|
|
|
|
|
|
assert.Check(t, flags.Set("config-file", configFile))
|
|
@@ -77,7 +81,7 @@ func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestLoadDaemonCliWithConflictingLabels(t *testing.T) {
|
|
|
- opts := defaultOptions("")
|
|
|
+ opts := defaultOptions(t, "")
|
|
|
flags := opts.flags
|
|
|
|
|
|
assert.Check(t, flags.Set("label", "foo=bar"))
|
|
@@ -88,7 +92,7 @@ func TestLoadDaemonCliWithConflictingLabels(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestLoadDaemonCliWithDuplicateLabels(t *testing.T) {
|
|
|
- opts := defaultOptions("")
|
|
|
+ opts := defaultOptions(t, "")
|
|
|
flags := opts.flags
|
|
|
|
|
|
assert.Check(t, flags.Set("label", "foo=the-same"))
|
|
@@ -102,7 +106,7 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(`{"tlsverify": true}`))
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
- opts := defaultOptions(tempFile.Path())
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
opts.TLSOptions.CAFile = "/tmp/ca.pem"
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
@@ -115,7 +119,7 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(`{"tlsverify": false}`))
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
- opts := defaultOptions(tempFile.Path())
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
opts.TLSOptions.CAFile = "/tmp/ca.pem"
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
@@ -128,7 +132,7 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(`{}`))
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
- opts := defaultOptions(tempFile.Path())
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
opts.TLSOptions.CAFile = "/tmp/ca.pem"
|
|
|
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
@@ -141,7 +145,7 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(`{"log-level": "warn"}`))
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
- opts := defaultOptions(tempFile.Path())
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
assert.NilError(t, err)
|
|
|
assert.Assert(t, loadedConfig != nil)
|
|
@@ -153,7 +157,7 @@ func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
- opts := defaultOptions(tempFile.Path())
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
assert.NilError(t, err)
|
|
|
assert.Assert(t, loadedConfig != nil)
|
|
@@ -170,7 +174,7 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
|
|
|
tempFile := fs.NewFile(t, "config", fs.WithContent(content))
|
|
|
defer tempFile.Remove()
|
|
|
|
|
|
- opts := defaultOptions(tempFile.Path())
|
|
|
+ opts := defaultOptions(t, tempFile.Path())
|
|
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
|
|
assert.NilError(t, err)
|
|
|
assert.Assert(t, loadedConfig != nil)
|