-
Notifications
You must be signed in to change notification settings - Fork 4
Setup e2e tests for some resources #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4764bdc
Setup e2e tests for domain
rocktavious 4f853cb
PR feedback
rocktavious f933a91
Checkpoint
rocktavious 2fe7e0b
Expand test coverage
rocktavious 821a698
Add system test
rocktavious b7fee17
First pass at fixing example command
rocktavious bebfe70
more tweaks
rocktavious 720052a
Fix CI
rocktavious e13b4ae
Fix up all example commands
rocktavious ec5bf41
More fixes
rocktavious 64b26d2
fixes
rocktavious 3684f29
more fixes for removal of old code
rocktavious 8f7d5eb
Update Taskfile.yml
rocktavious 0b3bdc4
fix e2e integration tests
rocktavious c09bb44
few more tweaks after testing manually
rocktavious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestDomainHappyPath(t *testing.T) { | ||
| createInput := ` | ||
| name: "Integration Test Domain" | ||
| description: "Created by integration test" | ||
| ` | ||
| updateInput1 := ` | ||
| name: "Integration Test Domain Updated" | ||
| description: "Updated by integration test" | ||
| ` | ||
| updateInput2 := ` | ||
| name: "Integration Test Domain Updated Again" | ||
| description: null | ||
| ` | ||
| domainName := "Integration Test Domain" | ||
| updatedDomainName := "Integration Test Domain Updated" | ||
| updatedAgainDomainName := "Integration Test Domain Updated Again" | ||
|
|
||
| test := CLITest{ | ||
| Create: Create("create domain -f -", createInput), | ||
| Get: Get("get domain"), | ||
| Delete: Delete("delete domain"), | ||
| Steps: []Step{ | ||
| func(u *Utility) { | ||
| out, err := u.Run("list domain") | ||
| if err != nil || !strings.Contains(out, domainName) { | ||
| u.Fatalf("list failed: %v\nout: %s", err, out) | ||
| } | ||
| }, | ||
| func(u *Utility) { | ||
| out, err := u.Run("update domain "+u.ID+" -f -", updateInput1) | ||
|
rocktavious marked this conversation as resolved.
Outdated
|
||
| if err != nil { | ||
| u.Fatalf("update1 failed: %v\nout: %s", err, out) | ||
| } | ||
| out, err = u.Run("get domain " + u.ID) | ||
| if err != nil || !strings.Contains(out, updatedDomainName) || !strings.Contains(out, "Updated by integration test") { | ||
| u.Fatalf("get after update1 failed: %v\nout: %s", err, out) | ||
| } | ||
| }, | ||
| func(u *Utility) { | ||
| out, err := u.Run("update domain "+u.ID+" -f -", updateInput2) | ||
|
rocktavious marked this conversation as resolved.
Outdated
|
||
| if err != nil { | ||
| u.Fatalf("update2 (unset) failed: %v\nout: %s", err, out) | ||
| } | ||
| out, err = u.Run("get domain " + u.ID) | ||
| if err != nil || !strings.Contains(out, updatedAgainDomainName) || strings.Contains(out, "Updated by integration test") { | ||
| u.Fatalf("get after update2 failed (description should be unset): %v\nout: %s", err, out) | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
| test.Run(t) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| type Utility struct { | ||
| *testing.T | ||
| ID string // The resource ID created by Create | ||
| } | ||
|
|
||
| // Run executes the CLI using 'go run main.go' from the ./src directory with the given arguments and optional stdin, returning combined output and error. | ||
| func (u *Utility) Run(args string, stdin ...string) (string, error) { | ||
| cmd := exec.Command("go", append([]string{"run", "main.go"}, strings.Split(args, " ")...)...) | ||
| cmd.Dir = ".." | ||
| cmd.Env = os.Environ() | ||
| var out bytes.Buffer | ||
| var errBuf bytes.Buffer | ||
| cmd.Stdout = &out | ||
| cmd.Stderr = &errBuf | ||
| if len(stdin) > 0 { | ||
| cmd.Stdin = strings.NewReader(stdin[0]) | ||
| } | ||
| err := cmd.Run() | ||
| return out.String() + errBuf.String(), err | ||
| } | ||
|
|
||
| type Step func(*Utility) | ||
|
|
||
| type CLITest struct { | ||
| Create Step | ||
| Get [2]Step | ||
| Delete Step | ||
| Steps []Step | ||
| } | ||
|
|
||
| func (ct *CLITest) Run(t *testing.T) { | ||
| util := &Utility{T: t} | ||
|
|
||
| defer func() { | ||
| if util.ID != "" { | ||
| ct.Delete(util) | ||
| } | ||
| }() | ||
|
|
||
| ct.Create(util) | ||
| ct.Get[0](util) // Should exist after create | ||
| for _, step := range ct.Steps { | ||
| step(util) | ||
| } | ||
| ct.Delete(util) | ||
| ct.Get[1](util) // Should not exist after delete | ||
| util.ID = "" // Mark as deleted so defer doesn't try again | ||
| } | ||
|
|
||
| func Create(cmd string, input string) Step { | ||
| return func(u *Utility) { | ||
| out, err := u.Run(cmd, input) | ||
| if err != nil { | ||
| u.Fatalf("create failed: %v\nout: %s", err, out) | ||
| } | ||
| u.ID = strings.TrimSpace(out) | ||
| if u.ID == "" { | ||
| u.Fatalf("expected ID, got: %q", out) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func Get(cmd string) [2]Step { | ||
| return [2]Step{func(u *Utility) { | ||
| out, err := u.Run(cmd + " " + u.ID) | ||
| if err != nil { | ||
| u.Fatalf("get failed: %v\nout: %s", err, out) | ||
| } | ||
| }, func(u *Utility) { | ||
| out, err := u.Run(cmd + " " + u.ID) | ||
| lower := strings.ToLower(out) | ||
| if err == nil || !(strings.Contains(lower, "not found") || strings.Contains(lower, "missing") || strings.Contains(lower, "gone")) { | ||
| u.Fatalf("expected get after delete to fail with not found, got: %v\nout: %s", err, out) | ||
| } | ||
| }} | ||
| } | ||
|
|
||
| func Delete(cmd string) Step { | ||
| return func(u *Utility) { | ||
| out, err := u.Run(cmd + " " + u.ID) | ||
| if err != nil { | ||
| u.Fatalf("delete failed: %v\nout: %s", err, out) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.