get.porter.sh/porter@v1.3.0/tests/integration/lifecycle_integration_test.go (about) 1 //go:build integration 2 3 package integration 4 5 import ( 6 "context" 7 "path/filepath" 8 "testing" 9 10 "get.porter.sh/porter/pkg/cnab" 11 "get.porter.sh/porter/pkg/porter" 12 "get.porter.sh/porter/pkg/storage" 13 "github.com/cnabio/cnab-go/bundle" 14 "github.com/cnabio/cnab-go/bundle/definition" 15 "github.com/stretchr/testify/require" 16 ) 17 18 var ( 19 kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest") 20 kahnlatestHash = "fd4bbe38665531d10bb653140842a370" 21 ) 22 23 func TestResolveBundleReference(t *testing.T) { 24 t.Parallel() 25 t.Run("current bundle source", func(t *testing.T) { 26 t.Parallel() 27 28 p := porter.NewTestPorter(t) 29 defer p.Close() 30 31 p.AddTestBundleDir(filepath.Join(p.RepoRoot, "tests/testdata/mybuns"), true) 32 33 opts := &porter.BundleReferenceOptions{} 34 require.NoError(t, opts.Validate(context.Background(), nil, p.Porter)) 35 ref, err := opts.GetBundleReference(context.Background(), p.Porter) 36 require.NoError(t, err) 37 require.NotEmpty(t, opts.Name) 38 require.NotEmpty(t, ref.Definition) 39 }) 40 41 t.Run("cnab file", func(t *testing.T) { 42 t.Parallel() 43 44 p := porter.NewTestPorter(t) 45 defer p.Close() 46 47 p.AddTestFile(filepath.Join(p.RepoRoot, "build/testdata/bundles/mysql/.cnab/bundle.json"), "bundle.json") 48 49 opts := &porter.BundleReferenceOptions{} 50 opts.CNABFile = "bundle.json" 51 require.NoError(t, opts.Validate(context.Background(), nil, p.Porter)) 52 ref, err := opts.GetBundleReference(context.Background(), p.Porter) 53 require.NoError(t, err) 54 require.NotEmpty(t, opts.Name) 55 require.NotEmpty(t, ref.Definition) 56 }) 57 58 t.Run("reference", func(t *testing.T) { 59 t.Parallel() 60 61 p := porter.NewTestPorter(t) 62 defer p.Close() 63 ctx := p.SetupIntegrationTest() 64 65 opts := &porter.BundleReferenceOptions{} 66 opts.Reference = "ghcr.io/getporter/examples/porter-hello:v0.2.0" 67 require.NoError(t, opts.Validate(ctx, nil, p.Porter)) 68 ref, err := opts.GetBundleReference(context.Background(), p.Porter) 69 require.NoError(t, err) 70 require.NotEmpty(t, opts.Name) 71 require.NotEmpty(t, ref.Definition) 72 require.NotEmpty(t, ref.RelocationMap) 73 require.NotEmpty(t, ref.Digest) 74 }) 75 76 t.Run("installation name", func(t *testing.T) { 77 t.Parallel() 78 79 p := porter.NewTestPorter(t) 80 defer p.Close() 81 82 bun := buildExampleBundle() 83 i := p.TestInstallations.CreateInstallation(storage.NewInstallation("dev", "example")) 84 p.TestInstallations.CreateRun(i.NewRun(cnab.ActionInstall, bun), func(r *storage.Run) { 85 r.BundleReference = kahnlatest.String() 86 r.Bundle = bun.Bundle 87 r.BundleDigest = kahnlatestHash 88 }) 89 opts := &porter.BundleReferenceOptions{} 90 opts.Name = "example" 91 opts.Namespace = "dev" 92 require.NoError(t, opts.Validate(context.Background(), nil, p.Porter)) 93 ref, err := opts.GetBundleReference(context.Background(), p.Porter) 94 require.NoError(t, err) 95 require.NotEmpty(t, opts.Name) 96 require.NotEmpty(t, ref.Definition) 97 require.NotEmpty(t, ref.Digest) 98 }) 99 } 100 101 func buildExampleBundle() cnab.ExtendedBundle { 102 bun := cnab.ExtendedBundle{Bundle: bundle.Bundle{ 103 SchemaVersion: bundle.GetDefaultSchemaVersion(), 104 InvocationImages: []bundle.InvocationImage{{BaseImage: bundle.BaseImage{Image: "example.com/foo:v1.0.0"}}}, 105 Actions: map[string]bundle.Action{ 106 "blah": { 107 Stateless: true, 108 }, 109 "other": { 110 Stateless: false, 111 Modifies: true, 112 }, 113 }, 114 Definitions: map[string]*definition.Schema{ 115 "porter-debug-parameter": { 116 Comment: "porter-internal", 117 ID: "https://porter.sh/generated-bundle/#porter-debug", 118 Default: false, 119 Description: "Print debug information from Porter when executing the bundle", 120 Type: "boolean", 121 }, 122 }, 123 Parameters: map[string]bundle.Parameter{ 124 "porter-debug": { 125 Definition: "porter-debug-parameter", 126 Description: "Print debug information from Porter when executing the bundle", 127 Destination: &bundle.Location{ 128 EnvironmentVariable: "PORTER_DEUBG", 129 }, 130 }, 131 }, 132 }} 133 return bun 134 }