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

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"testing"
     7  
     8  	"get.porter.sh/porter/tests"
     9  	"get.porter.sh/porter/tests/testdata"
    10  	"get.porter.sh/porter/tests/tester"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestUninstall_DeleteInstallation(t *testing.T) {
    15  	test, err := tester.NewTest(t)
    16  	defer test.Close()
    17  	require.NoError(t, err, "test setup failed")
    18  	test.PrepareTestBundle()
    19  
    20  	// Check that we can't uninstall a bundle that hasn't been installed already
    21  	_, _, err = test.RunPorter("uninstall", testdata.MyBuns, "-c=mybuns")
    22  	test.RequireNotFoundReturned(err)
    23  
    24  	// Install bundle
    25  	test.RequirePorter("install", testdata.MyBuns, "-r", testdata.MyBunsRef, "-c=mybuns", "--param", "password=supersecret")
    26  
    27  	// Uninstall the bundle
    28  	test.RequirePorter("uninstall", testdata.MyBuns, "-c=mybuns", "--param", "password=supersecret")
    29  
    30  	// Check that the record remains
    31  	test.RequireInstallationExists(test.CurrentNamespace(), testdata.MyBuns)
    32  
    33  	// Uninstall and delete
    34  	test.RequirePorter("uninstall", testdata.MyBuns, "-c=mybuns", "--delete", "--param", "password=supersecret")
    35  
    36  	// The record should be gone
    37  	test.RequireInstallationNotFound(test.CurrentNamespace(), testdata.MyBuns)
    38  
    39  	// Re-Install the bundle
    40  	test.RequirePorter("install", testdata.MyBuns, "-r", testdata.MyBunsRef, "-c=mybuns", "--param", "password=supersecret")
    41  
    42  	// Uninstall the bundle, attempt to delete it, but have the uninstall fail
    43  	_, _, err = test.RunPorter("uninstall", testdata.MyBuns, "-c=mybuns", "--param", "chaos_monkey=true", "--delete", "--param", "password=supersecret")
    44  	tests.RequireErrorContains(t, err, "it is unsafe to delete an installation when the last action wasn't a successful uninstall")
    45  
    46  	// Check that the record remains
    47  	test.RequireInstallationExists(test.CurrentNamespace(), testdata.MyBuns)
    48  
    49  	// Uninstall the bundle, even though uninstall is failing, and force delete it
    50  	test.RequirePorter("uninstall", testdata.MyBuns, "-c=mybuns", "--force-delete", "--param", "password=supersecret")
    51  
    52  	// The record should be gone
    53  	test.RequireInstallationNotFound(test.CurrentNamespace(), testdata.MyBuns)
    54  }