|
| 1 | +//go:build integration |
| 2 | + |
| 3 | +package main |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "os" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/carapace-sh/carapace" |
| 12 | + "github.com/carapace-sh/carapace-aws/cmd/carapace-aws/cmd/botocore" |
| 13 | + "github.com/carapace-sh/carapace-bridge/pkg/actions/bridge" |
| 14 | +) |
| 15 | + |
| 16 | +func TestService(t *testing.T) { |
| 17 | + serviceToTest := os.Getenv("SERVICE") |
| 18 | + for service := range botocore.Services() { |
| 19 | + t.Run(service, func(t *testing.T) { |
| 20 | + if serviceToTest != "" && service != serviceToTest { // TODO env var to only test a specific service |
| 21 | + t.SkipNow() |
| 22 | + } |
| 23 | + |
| 24 | + patch := carapace.DiffPatch( |
| 25 | + bridge.ActionAws("aws"), |
| 26 | + bridge.ActionCarapaceBin("aws"), |
| 27 | + carapace.NewContext(service, ""), |
| 28 | + ) |
| 29 | + for _, line := range patch { |
| 30 | + switch { |
| 31 | + case strings.HasPrefix(line, "-"): |
| 32 | + fmt.Printf("\033[0;31m%v\033[0m\n", line) |
| 33 | + t.Fail() |
| 34 | + case strings.HasPrefix(line, "+"): |
| 35 | + fmt.Printf("\033[0;32m%v\033[0m\n", line) |
| 36 | + t.Fail() |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + for operation := range botocore.Operations("ec2") { |
| 41 | + t.Run(operation, func(t *testing.T) { |
| 42 | + t.Parallel() |
| 43 | + patch := carapace.DiffPatch( |
| 44 | + bridge.ActionAws("aws"), |
| 45 | + bridge.ActionCarapaceBin("aws"), |
| 46 | + carapace.NewContext(service, operation, "--"), |
| 47 | + ) |
| 48 | + for _, line := range patch { |
| 49 | + switch { |
| 50 | + case strings.HasPrefix(line, "-"): |
| 51 | + fmt.Printf("\033[0;31m%v\033[0m\n", line) |
| 52 | + t.Fail() |
| 53 | + case strings.HasPrefix(line, "+"): |
| 54 | + fmt.Printf("\033[0;32m%v\033[0m\n", line) |
| 55 | + t.Fail() |
| 56 | + } |
| 57 | + } |
| 58 | + }) |
| 59 | + } |
| 60 | + }) |
| 61 | + } |
| 62 | +} |
0 commit comments