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

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	migrationhelpers "get.porter.sh/porter/pkg/storage/migrations/testhelpers"
    11  	testhelpers "get.porter.sh/porter/pkg/test"
    12  	"get.porter.sh/porter/tests/tester"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  // Do a migration. This also checks for any problems with our
    17  // connection handling which can result in panics :-)
    18  func TestMigration(t *testing.T) {
    19  	t.Parallel()
    20  
    21  	test, err := tester.NewTest(t)
    22  	defer test.Close()
    23  	require.NoError(t, err, "test setup failed")
    24  
    25  	testdata := filepath.Join(test.RepoRoot, "tests/integration/testdata/migration/")
    26  
    27  	// Set up a PORTER_HOME with v0.38 data
    28  	oldCfg := migrationhelpers.CreateLegacyPorterHome(t)
    29  	defer oldCfg.Close()
    30  	oldHome, err := oldCfg.GetHomeDir()
    31  
    32  	// Migrate their data
    33  	destNamespace := "migrated"
    34  	_, output := test.RequirePorter("storage", "migrate", "--old-home", oldHome, "--old-account=src", "--namespace", destNamespace)
    35  
    36  	// Verify that the installations were migrated to the specified namespace
    37  	output, _ = test.RequirePorter("list", "--namespace", destNamespace, "--output=json", "--verbosity=info")
    38  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installations-list-output.json"), output)
    39  
    40  	// Verify that all the previous runs were migrated
    41  	output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "hello1", "--output=json", "--verbosity=info")
    42  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-hello1-output.json"), output)
    43  
    44  	output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "hello-llama", "--output=json", "--verbosity=info")
    45  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-hello-llama-output.json"), output)
    46  
    47  	output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "creds-tutorial", "--output=json", "--verbosity=info")
    48  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-creds-tutorial-output.json"), output)
    49  
    50  	output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "sensitive-data", "--output=json", "--verbosity=info")
    51  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-sensitive-data-output.json"), output)
    52  
    53  	// Verify that outputs were migrated, all the installations except sensitive-data only have logs (which aren't printed by installation outputs list)
    54  	// Show the logs from installing hello1
    55  	output, _ = test.RequirePorter("installation", "logs", "show", "--namespace", destNamespace, "-r=01G1VJGY43HT3KZN82DS6DDPWK", "--verbosity=info")
    56  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "logs-install-hello1.txt"), output)
    57  
    58  	// Show the logs from the last run of hello-llama
    59  	output, _ = test.RequirePorter("installation", "logs", "show", "--namespace", destNamespace, "-i=hello-llama", "--verbosity=info")
    60  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "logs-hello-llama.txt"), output)
    61  
    62  	// Show the outputs of the sensitive-data bundle
    63  	output, _ = test.RequirePorter("installation", "outputs", "list", "--namespace", destNamespace, "sensitive-data", "--output=json", "--verbosity=info")
    64  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "outputs-list-sensitive-data-output.json"), output)
    65  
    66  	// Dump out the migrated installations and make sure that all the fields are set correctly
    67  	output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "hello1", "--output=json", "--verbosity=info")
    68  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-hello1-output.json"), output)
    69  
    70  	output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "hello-llama", "--output=json", "--verbosity=info")
    71  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-hello-llama-output.json"), output)
    72  
    73  	output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "creds-tutorial", "--output=json", "--verbosity=info")
    74  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-creds-tutorial-output.json"), output)
    75  
    76  	output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "sensitive-data", "--output=json", "--verbosity=info")
    77  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-sensitive-data-output.json"), output)
    78  
    79  	// Verify that the sensitive-data installation stored sensitive values in the secret store
    80  	secretsDir := filepath.Join(test.PorterHomeDir, "secrets")
    81  	secretOutput, err := os.ReadFile(filepath.Join(secretsDir, "01G6K8CZ08T78WXTJYHR0NTYBS-name"))
    82  	require.NoError(t, err, "Failed to read the secrets file for the sensitive output: name")
    83  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "secrets/01G6K8CZ08T78WXTJYHR0NTYBS-name"), string(secretOutput))
    84  	secretParam, err := os.ReadFile(filepath.Join(secretsDir, "01G6K8CZ08T78WXTJYHR0NTYBS-password"))
    85  	require.NoError(t, err, "Failed to read the secrets file for the sensitive parameter: password")
    86  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "secrets/01G6K8CZ08T78WXTJYHR0NTYBS-password"), string(secretParam))
    87  
    88  	// Verify that the parameter sets were migrated to the specified namespace
    89  	output, _ = test.RequirePorter("parameters", "list", "--namespace", destNamespace, "--output=json", "--verbosity=info")
    90  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "parameters-list-output.json"), output)
    91  
    92  	// Dump out the migrated parameter sets and make sure that all the fields are set correctly
    93  	output, _ = test.RequirePorter("parameters", "show", "--namespace", destNamespace, "hello-llama", "--output=json", "--verbosity=info")
    94  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "parameters-show-hello-llama-output.json"), output)
    95  
    96  	// Verify that the credential sets were migrated to the specified namespace
    97  	output, _ = test.RequirePorter("credentials", "list", "--namespace", destNamespace, "--output=json", "--verbosity=info")
    98  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "credentials-list-output.json"), output)
    99  
   100  	// Dump out the migrated credential sets and make sure that all the fields are set correctly
   101  	output, _ = test.RequirePorter("credentials", "show", "--namespace", destNamespace, "credentials-tutorial", "--output=json", "--verbosity=info")
   102  	testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "credentials-show-credentials-tutorial-output.json"), output)
   103  }