mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape/discovery/kubernetes/kubeconfig_test.go: make TestParseKubeConfigSuccess test code easier to follow
This commit is contained in:
parent
eed5206376
commit
c22e3e7b1d
1 changed files with 28 additions and 46 deletions
|
@ -8,57 +8,39 @@ import (
|
|||
)
|
||||
|
||||
func TestParseKubeConfigSuccess(t *testing.T) {
|
||||
f := func(configFile string, expectedConfig *kubeConfig) {
|
||||
t.Helper()
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
kubeConfigFile string
|
||||
expectedConfig *kubeConfig
|
||||
config, err := newKubeConfig(configFile)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(config, expectedConfig) {
|
||||
t.Fatalf("unexpected result, got: %v, want: %v", config, expectedConfig)
|
||||
}
|
||||
}
|
||||
|
||||
var cases = []testCase{
|
||||
{
|
||||
name: "token",
|
||||
kubeConfigFile: "testdata/good_kubeconfig/with_token.yaml",
|
||||
expectedConfig: &kubeConfig{
|
||||
server: "http://some-server:8080",
|
||||
token: "abc",
|
||||
},
|
||||
f("testdata/good_kubeconfig/with_token.yaml", &kubeConfig{
|
||||
server: "http://some-server:8080",
|
||||
token: "abc",
|
||||
})
|
||||
|
||||
f("testdata/good_kubeconfig/with_tls.yaml", &kubeConfig{
|
||||
server: "https://localhost:6443",
|
||||
tlsConfig: &promauth.TLSConfig{
|
||||
CA: "authority",
|
||||
Cert: "certificate",
|
||||
Key: "key",
|
||||
},
|
||||
{
|
||||
name: "cert",
|
||||
kubeConfigFile: "testdata/good_kubeconfig/with_tls.yaml",
|
||||
expectedConfig: &kubeConfig{
|
||||
server: "https://localhost:6443",
|
||||
tlsConfig: &promauth.TLSConfig{
|
||||
CA: "authority",
|
||||
Cert: "certificate",
|
||||
Key: "key",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
f("testdata/good_kubeconfig/with_basic.yaml", &kubeConfig{
|
||||
server: "http://some-server:8080",
|
||||
basicAuth: &promauth.BasicAuthConfig{
|
||||
Password: promauth.NewSecret("secret"),
|
||||
Username: "user1",
|
||||
},
|
||||
{
|
||||
name: "basic",
|
||||
kubeConfigFile: "testdata/good_kubeconfig/with_basic.yaml",
|
||||
expectedConfig: &kubeConfig{
|
||||
server: "http://some-server:8080",
|
||||
basicAuth: &promauth.BasicAuthConfig{
|
||||
Password: promauth.NewSecret("secret"),
|
||||
Username: "user1",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ac, err := newKubeConfig(tc.kubeConfigFile)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(ac, tc.expectedConfig) {
|
||||
t.Fatalf("unexpected result, got: %v, want: %v", ac, tc.expectedConfig)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseKubeConfigFail(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue