(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestEnvPerfOpsAPIKey(t *testing.T) { |
| 32 | os.Unsetenv("PERFOPS_API_KEY") |
| 33 | |
| 34 | rootCmd.ResetFlags() |
| 35 | initRootCmd() |
| 36 | if err := rootCmd.ParseFlags([]string{}); err != nil { |
| 37 | t.Fatalf("exepected nil; got %v", err) |
| 38 | } |
| 39 | if err := rootCmd.Execute(); err != nil { |
| 40 | t.Fatalf("exepected nil; got %v", err) |
| 41 | } |
| 42 | if got := apiKey; got != "" { |
| 43 | t.Fatalf("expected no key; got %v", got) |
| 44 | } |
| 45 | |
| 46 | const apiKey2 = "Moo" |
| 47 | rootCmd.ResetFlags() |
| 48 | initRootCmd() |
| 49 | if err := rootCmd.ParseFlags([]string{"-K", apiKey2}); err != nil { |
| 50 | t.Fatalf("exepected nil; got %v", err) |
| 51 | } |
| 52 | if err := rootCmd.Execute(); err != nil { |
| 53 | t.Fatalf("exepected nil; got %v", err) |
| 54 | } |
| 55 | if got := apiKey; got != apiKey2 { |
| 56 | t.Fatalf("expected %v; got %v", apiKey2, got) |
| 57 | } |
| 58 | |
| 59 | const envAPIKey = "Meep" |
| 60 | os.Setenv("PERFOPS_API_KEY", envAPIKey) |
| 61 | defer os.Unsetenv("PERFOPS_API_KEY") |
| 62 | rootCmd.ResetFlags() |
| 63 | initRootCmd() |
| 64 | if err := rootCmd.ParseFlags([]string{}); err != nil { |
| 65 | t.Fatalf("exepected nil; got %v", err) |
| 66 | } |
| 67 | if err := rootCmd.Execute(); err != nil { |
| 68 | t.Fatalf("exepected nil; got %v", err) |
| 69 | } |
| 70 | if got := apiKey; got != envAPIKey { |
| 71 | t.Fatalf("expected %v; got %v", envAPIKey, got) |
| 72 | } |
| 73 | |
| 74 | rootCmd.ResetFlags() |
| 75 | initRootCmd() |
| 76 | if err := rootCmd.ParseFlags([]string{"-K", apiKey2}); err != nil { |
| 77 | t.Fatalf("exepected nil; got %v", err) |
| 78 | } |
| 79 | if err := rootCmd.Execute(); err != nil { |
| 80 | t.Fatalf("exepected nil; got %v", err) |
| 81 | } |
| 82 | if got := apiKey; got != apiKey2 { |
| 83 | t.Fatalf("expected %v; got %v", apiKey2, got) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | func TestVersionFlag(t *testing.T) { |
| 88 | versionOutput := fmt.Sprintf(versionTmpl, version, buildDate, commitHash, |
nothing calls this directly
no test coverage detected