| 238 | } |
| 239 | |
| 240 | func TestInitDbxSkipsAuthForLocalCommands(t *testing.T) { |
| 241 | t.Setenv(envAccessToken, "") |
| 242 | t.Setenv(envAuthFile, filepath.Join(t.TempDir(), "missing-auth.json")) |
| 243 | |
| 244 | tests := []struct { |
| 245 | name string |
| 246 | cmd *cobra.Command |
| 247 | }{ |
| 248 | { |
| 249 | name: "version", |
| 250 | cmd: &cobra.Command{Use: "version"}, |
| 251 | }, |
| 252 | { |
| 253 | name: "help", |
| 254 | cmd: &cobra.Command{Use: "help"}, |
| 255 | }, |
| 256 | { |
| 257 | name: "completion", |
| 258 | cmd: func() *cobra.Command { |
| 259 | root := &cobra.Command{Use: "dbxcli"} |
| 260 | completion := &cobra.Command{Use: "completion"} |
| 261 | bash := &cobra.Command{Use: "bash"} |
| 262 | completion.AddCommand(bash) |
| 263 | root.AddCommand(completion) |
| 264 | return bash |
| 265 | }(), |
| 266 | }, |
| 267 | { |
| 268 | name: "complete", |
| 269 | cmd: &cobra.Command{Use: "__complete"}, |
| 270 | }, |
| 271 | { |
| 272 | name: "complete-no-desc", |
| 273 | cmd: &cobra.Command{Use: "__completeNoDesc"}, |
| 274 | }, |
| 275 | } |
| 276 | |
| 277 | for _, tt := range tests { |
| 278 | t.Run(tt.name, func(t *testing.T) { |
| 279 | if err := initDbx(tt.cmd, nil); err != nil { |
| 280 | t.Fatalf("expected auth to be skipped, got %v", err) |
| 281 | } |
| 282 | }) |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func TestInitCommandContextUsesTimeout(t *testing.T) { |
| 287 | t.Cleanup(finishCommandContext) |