get.porter.sh/porter@v1.3.0/tests/integration/driver_test.go (about)

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	"get.porter.sh/porter/tests"
    11  	"get.porter.sh/porter/tests/testdata"
    12  	"get.porter.sh/porter/tests/tester"
    13  	"github.com/stretchr/testify/require"
    14  	"github.com/uwu-tools/magex/shx"
    15  )
    16  
    17  // Validate that we can use PORTER_RUNTIME_DRIVER with
    18  // porter commands and have that set the --driver flag.
    19  func TestBindRuntimeDriverConfiguration(t *testing.T) {
    20  	test, err := tester.NewTest(t)
    21  	defer test.Close()
    22  	require.NoError(t, err, "test setup failed")
    23  
    24  	require.NoError(t, shx.Copy(filepath.Join(test.RepoRoot, "tests/testdata/installations/mybuns.yaml"), test.TestDir))
    25  	test.Chdir(test.TestDir)
    26  
    27  	// Set the driver to something that will fail validation so we know it was picked up
    28  	os.Setenv("PORTER_RUNTIME_DRIVER", "fake")
    29  	defer os.Unsetenv("PORTER_RUNTIME_DRIVER")
    30  
    31  	// Check that the imperative commands are using this environment variable
    32  	_, _, err = test.RunPorter("install", testdata.MyBuns)
    33  	tests.RequireErrorContains(t, err, "unsupported driver", "install does not have --driver wired properly")
    34  
    35  	_, _, err = test.RunPorter("upgrade", testdata.MyBuns)
    36  	tests.RequireErrorContains(t, err, "unsupported driver", "upgrade does not have --driver wired properly")
    37  
    38  	_, _, err = test.RunPorter("invoke", testdata.MyBuns, "--action=ping")
    39  	tests.RequireErrorContains(t, err, "unsupported driver", "invoke does not have --driver wired properly")
    40  
    41  	_, _, err = test.RunPorter("uninstall", testdata.MyBuns)
    42  	tests.RequireErrorContains(t, err, "unsupported driver", "uninstall does not have --driver wired properly")
    43  
    44  	test.PrepareTestBundle() // apply tries to pull the bundle before the driver flag is validated
    45  	_, output, _ := test.RunPorter("installation", "apply", "mybuns.yaml")
    46  	tests.RequireOutputContains(t, output, "unsupported driver", "apply does not have --driver wired properly")
    47  }
    48  
    49  // Validate that we can use PORTER_BUILD_DRIVER with
    50  // porter build and have that set the --driver flag.
    51  func TestBindBuildDriverConfiguration(t *testing.T) {
    52  	test, err := tester.NewTest(t)
    53  	defer test.Close()
    54  	require.NoError(t, err, "test setup failed")
    55  
    56  	// Set the driver to something that will fail validation so we know it was picked up
    57  	os.Setenv("PORTER_BUILD_DRIVER", "fake")
    58  	defer os.Unsetenv("PORTER_BUILD_DRIVER")
    59  
    60  	t.Run("build", func(t *testing.T) {
    61  		_, _, err = test.RunPorter("build")
    62  		tests.RequireErrorContains(t, err, "invalid --driver")
    63  	})
    64  }