MCPcopy
hub / github.com/kubernetes/client-go / TestConfigStringer

Function TestConfigStringer

rest/config_test.go:381–465  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

379}
380
381func TestConfigStringer(t *testing.T) {
382 formatBytes := func(b []byte) string {
383 // %#v for []byte always pre-pends "[]byte{".
384 // %#v for struct with []byte field always pre-pends "[]uint8{".
385 return strings.Replace(fmt.Sprintf("%#v", b), "byte", "uint8", 1)
386 }
387 tests := []struct {
388 desc string
389 c *Config
390 expectContent []string
391 prohibitContent []string
392 }{
393 {
394 desc: "nil config",
395 c: nil,
396 expectContent: []string{"<nil>"},
397 },
398 {
399 desc: "non-sensitive config",
400 c: &Config{
401 Host: "localhost:8080",
402 APIPath: "v1",
403 UserAgent: "gobot",
404 },
405 expectContent: []string{"localhost:8080", "v1", "gobot"},
406 },
407 {
408 desc: "sensitive config",
409 c: &Config{
410 Host: "localhost:8080",
411 Username: "gopher",
412 Password: "g0ph3r",
413 BearerToken: "1234567890",
414 TLSClientConfig: TLSClientConfig{
415 CertFile: "a.crt",
416 KeyFile: "a.key",
417 CertData: []byte("fake cert"),
418 KeyData: []byte("fake key"),
419 },
420 AuthProvider: &clientcmdapi.AuthProviderConfig{
421 Config: map[string]string{"secret": "s3cr3t"},
422 },
423 ExecProvider: &clientcmdapi.ExecConfig{
424 Args: []string{"secret"},
425 Env: []clientcmdapi.ExecEnvVar{{Name: "secret", Value: "s3cr3t"}},
426 },
427 },
428 expectContent: []string{
429 "localhost:8080",
430 "gopher",
431 "a.crt",
432 "a.key",
433 "--- REDACTED ---",
434 formatBytes([]byte("--- REDACTED ---")),
435 formatBytes([]byte("--- TRUNCATED ---")),
436 },
437 prohibitContent: []string{
438 "g0ph3r",

Callers

nothing calls this directly

Calls 5

ReplaceMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65
LogfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected