This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from stealthrocket/cli-tests
timecraft: add tests for CLI
- Loading branch information
Showing
23 changed files
with
264 additions
and
135 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,39 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stealthrocket/timecraft/internal/cmd" | ||
) | ||
|
||
func ExampleRoot_profileMissingID() { | ||
ctx := context.Background() | ||
|
||
FAIL(cmd.Root(ctx, "profile")) | ||
// Output: | ||
// ERR: timecraft profile: expected exactly one process id as argument | ||
} | ||
|
||
func ExampleRoot_profileTooManyArgs() { | ||
ctx := context.Background() | ||
|
||
FAIL(cmd.Root(ctx, "profile", "1", "2", "3")) | ||
// Output: | ||
// ERR: timecraft profile: expected exactly one process id as argument | ||
} | ||
|
||
func ExampleRoot_profileInvalidID() { | ||
ctx := context.Background() | ||
|
||
FAIL(cmd.Root(ctx, "profile", "1234567890")) | ||
// Output: | ||
// ERR: timecraft profile: malformed process id passed as argument (not a UUID) | ||
} | ||
|
||
func ExampleRoot_profileUnknownID() { | ||
ctx := context.Background() | ||
|
||
FAIL(cmd.Root(ctx, "profile", "b0f4dac5-9855-4cde-89fd-ebd3713c2249")) | ||
// Output: | ||
// ERR: timecraft profile: process has no records: b0f4dac5-9855-4cde-89fd-ebd3713c2249 | ||
} |
This file contains 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 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 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,18 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func PASS(rc int) { | ||
if rc != 0 { | ||
fmt.Fprintf(os.Stderr, "exit: %d\n", rc) | ||
} | ||
} | ||
|
||
func FAIL(rc int) { | ||
if rc != 1 { | ||
fmt.Fprintf(os.Stderr, "exit: %d\n", rc) | ||
} | ||
} |
This file contains 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 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,22 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stealthrocket/timecraft/internal/cmd" | ||
) | ||
|
||
func ExampleRoot_runExitZero() { | ||
ctx := context.Background() | ||
|
||
PASS(cmd.Root(ctx, "run", "../../testdata/go/sleep.wasm", "10ms")) | ||
// Output: sleeping for 10ms | ||
} | ||
|
||
func ExampleRoot_runContextCanceled() { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
cancel() | ||
|
||
PASS(cmd.Root(ctx, "run", "../../testdata/go/sleep.wasm", "10s")) | ||
// Output: | ||
} |
This file contains 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 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,15 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stealthrocket/timecraft/internal/cmd" | ||
) | ||
|
||
func ExampleRoot_version() { | ||
ctx := context.Background() | ||
|
||
PASS(cmd.Root(ctx, "version")) | ||
// Output: | ||
// timecraft devel | ||
} |
This file contains 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 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 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
Oops, something went wrong.