-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error out when config file contains 1.x config values (#22996)
* feat: error out when config file contains invalid options * feat: debug logging when loading a config file * fix: only detect flags from 1.x * test: update tests to use toml configs
- Loading branch information
1 parent
6023496
commit c51a0df
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package launcher | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestInvalidFlags(t *testing.T) { | ||
t.Parallel() | ||
|
||
v2config := ` | ||
bolt-path = "/db/.influxdbv2/influxd.bolt" | ||
engine-path = "/db/.influxdbv2/engine" | ||
http-bind-address = ":8086" | ||
` | ||
|
||
v1config := ` | ||
reporting-disabled = false | ||
# Bind address to use for the RPC service for backup and restore. | ||
bind-address = "127.0.0.1:8088" | ||
[http] | ||
flux-enabled = false | ||
[data] | ||
index-version = "inmem"` | ||
|
||
tests := []struct { | ||
name string | ||
config string | ||
want []string | ||
}{ | ||
{ | ||
name: "empty config", | ||
config: "", | ||
want: []string(nil), | ||
}, | ||
{ | ||
name: "v2 config", | ||
config: v2config, | ||
want: []string(nil), | ||
}, | ||
{ | ||
name: "v1 config", | ||
config: v1config, | ||
want: []string{"http.flux-enabled", "data.index-version", "bind-address"}, | ||
}, | ||
{ | ||
name: "mixed config", | ||
config: v2config + v1config, | ||
want: []string{"http.flux-enabled", "data.index-version", "bind-address"}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := strings.NewReader(tt.config) | ||
v := viper.GetViper() | ||
v.SetConfigType("toml") | ||
require.NoError(t, v.ReadConfig(r)) | ||
got := invalidFlags(v) | ||
require.ElementsMatch(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters