forked from getporter/porter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setting --driver with env variables
This binds the --driver flag for porter install|invoke|upgrade|uninstall to the PORTER_RUNTIME_DRIVER environment variable used by the operator. I had already done this for PORTER_BUILD_DRIVER, but missed adding similar configuration bindings for runtime. So in the config file, the user can set rutime-driver and build-driver. The environment variables are named: PORTER_RUNTIME_DRIVER and PORTER_BUILD_DRIVER. The flag though on any command is just --driver for simplicity, e.g. porter install --driver kubernetes. Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com> Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
- Loading branch information
1 parent
becc618
commit 685e1de
Showing
12 changed files
with
103 additions
and
13 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
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,64 @@ | ||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"get.porter.sh/porter/tests" | ||
"get.porter.sh/porter/tests/testdata" | ||
"get.porter.sh/porter/tests/tester" | ||
"github.com/carolynvs/magex/shx" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Validate that we can use PORTER_RUNTIME_DRIVER with | ||
// porter commands and have that set the --driver flag. | ||
func TestBindRuntimeDriverConfiguration(t *testing.T) { | ||
test, err := tester.NewTest(t) | ||
defer test.Teardown() | ||
require.NoError(t, err, "test setup failed") | ||
|
||
require.NoError(t, shx.Copy(filepath.Join(test.RepoRoot, "tests/testdata/installations/mybuns.yaml"), test.TestDir)) | ||
test.Chdir(test.TestDir) | ||
|
||
// Set the driver to something that will fail validation so we know it was picked up | ||
os.Setenv("PORTER_RUNTIME_DRIVER", "fake") | ||
defer os.Unsetenv("PORTER_RUNTIME_DRIVER") | ||
|
||
// Check that the imperative commands are using this environment variable | ||
_, _, err = test.RunPorter("install", testdata.MyBuns) | ||
tests.RequireErrorContains(t, err, "unsupported driver", "install does not have --driver wired properly") | ||
|
||
_, _, err = test.RunPorter("upgrade", testdata.MyBuns) | ||
tests.RequireErrorContains(t, err, "unsupported driver", "upgrade does not have --driver wired properly") | ||
|
||
_, _, err = test.RunPorter("invoke", testdata.MyBuns, "--action=ping") | ||
tests.RequireErrorContains(t, err, "unsupported driver", "invoke does not have --driver wired properly") | ||
|
||
_, _, err = test.RunPorter("uninstall", testdata.MyBuns) | ||
tests.RequireErrorContains(t, err, "unsupported driver", "uninstall does not have --driver wired properly") | ||
|
||
test.PrepareTestBundle() // apply tries to pull the bundle before the driver flag is validated | ||
_, _, err = test.RunPorter("installation", "apply", "mybuns.yaml") | ||
tests.RequireErrorContains(t, err, "unsupported driver", "apply does not have --driver wired properly") | ||
} | ||
|
||
// Validate that we can use PORTER_BUILD_DRIVER with | ||
// porter build and have that set the --driver flag. | ||
func TestBindBuildDriverConfiguration(t *testing.T) { | ||
test, err := tester.NewTest(t) | ||
defer test.Teardown() | ||
require.NoError(t, err, "test setup failed") | ||
|
||
// Set the driver to something that will fail validation so we know it was picked up | ||
os.Setenv("PORTER_BUILD_DRIVER", "fake") | ||
defer os.Unsetenv("PORTER_BUILD_DRIVER") | ||
|
||
t.Run("build", func(t *testing.T) { | ||
_, _, err = test.RunPorter("build") | ||
tests.RequireErrorContains(t, err, "invalid --driver") | ||
}) | ||
} |