-
Notifications
You must be signed in to change notification settings - Fork 212
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 #717 from carolynvs/expect-multiple-commands
Add testing page for mixin developers
- Loading branch information
Showing
11 changed files
with
79 additions
and
22 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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
--- | ||
title: Developing Mixins | ||
description: Creating and Extending Mixins for Porter | ||
layout: single | ||
--- | ||
|
||
The easiest way to make a mixin right now is to use start from our template repository: | ||
|
||
<https://github.com/deislabs/porter-skeletor> | ||
|
||
## See Also | ||
* [Mixin Commands](./commands/) | ||
* [Mixin Architecture](./architecture/) | ||
* [Mixin Distribution](./distribution/) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,51 @@ | ||
--- | ||
title: Testing a Mixin | ||
description: How to test a Porter mixin | ||
--- | ||
|
||
We are working on filling this doc out more, until then this is more of a FAQ than a proscriptive guide. If you have | ||
a tip, please submit a PR and help us fill this out! | ||
|
||
## How do I unit test that my mixin is executing the right commands? | ||
|
||
Here is a [full working example][example] of a unit test that validates the commands executed by a mixin. | ||
|
||
Make sure that your package has a `TestMain` that calls `github.com/deislabs/porter/pkg/test.TestMainWithMockedCommandHandlers` | ||
|
||
```go | ||
import "github.com/deislabs/porter/pkg/test" | ||
|
||
func TestMain(m *testing.M) { | ||
test.TestMainWithMockedCommandHandlers(m) | ||
} | ||
``` | ||
|
||
Then you instantiate your mixin in test mode (the skeletor template generates this method for you): | ||
|
||
```go | ||
m := NewTestMixin(t) | ||
``` | ||
|
||
This sets up your test binary to assert that expected command(s) were called. You tell it what command to expect with | ||
|
||
```go | ||
os.Setenv(test.ExpectedCommandEnv, "helm install") | ||
defer os.Unsetenv(test.ExpectedCommandEnv) | ||
``` | ||
|
||
If your mixin action executes multiple commands, separate them with a newline `\n` like so | ||
|
||
```go | ||
os.Setenv(test.ExpectedCommandEnv, "helm install\nhelm upgrade") | ||
``` | ||
|
||
Now execute your mixin action: | ||
|
||
```go | ||
err = m.Execute() | ||
``` | ||
|
||
Instead of os calls to the real commands, the test mixin mode calls back into your test binary. The `TestMain` handles | ||
asserting that the expected commands were made and fails the test if they weren't. | ||
|
||
[example]: https://github.com/deislabs/porter-gcloud/blob/v0.2.1-beta.1/pkg/gcloud/execute_test.go |
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