diff --git a/pkg/porter/run.go b/pkg/porter/run.go index 16c92d1a9..3735e1f05 100644 --- a/pkg/porter/run.go +++ b/pkg/porter/run.go @@ -90,7 +90,7 @@ func (p *Porter) Run(ctx context.Context, opts RunOptions) error { return span.Error(err) } - runtimeCfg := runtime.NewConfigFor(p.Context) + runtimeCfg := runtime.NewConfigFor(p.Config) runtimeCfg.DebugMode = opts.DebugMode r := runtime.NewPorterRuntime(runtimeCfg, p.Mixins) runtimeManifest := r.NewRuntimeManifest(opts.Action, m) diff --git a/pkg/runtime/context.go b/pkg/runtime/context.go index dbb561d76..c1c03059f 100644 --- a/pkg/runtime/context.go +++ b/pkg/runtime/context.go @@ -5,12 +5,11 @@ import ( "strconv" "get.porter.sh/porter/pkg/config" - "get.porter.sh/porter/pkg/portercontext" ) -// RuntimeConfig is a specialized portercontext.Context with additional runtime-specific settings. +// RuntimeConfig is a specialized config.Config with additional runtime-specific settings. type RuntimeConfig struct { - *portercontext.Context + *config.Config // DebugMode indicates if the bundle is running in debug mode. DebugMode bool @@ -18,15 +17,15 @@ type RuntimeConfig struct { // NewConfig returns an initialized RuntimeConfig func NewConfig() RuntimeConfig { - return NewConfigFor(portercontext.New()) + return NewConfigFor(config.New()) } // NewConfigFor returns an initialized RuntimeConfig using the specified context. -func NewConfigFor(porterCtx *portercontext.Context) RuntimeConfig { - debug, _ := strconv.ParseBool(porterCtx.Getenv("PORTER_DEBUG")) +func NewConfigFor(config *config.Config) RuntimeConfig { + debug, _ := strconv.ParseBool(config.Getenv("PORTER_DEBUG")) return RuntimeConfig{ - Context: porterCtx, DebugMode: debug, + Config: config, } } diff --git a/pkg/runtime/context_test.go b/pkg/runtime/context_test.go index e55c4a661..a15482bb6 100644 --- a/pkg/runtime/context_test.go +++ b/pkg/runtime/context_test.go @@ -3,7 +3,7 @@ package runtime import ( "testing" - "get.porter.sh/porter/pkg/portercontext" + "get.porter.sh/porter/pkg/config" "github.com/stretchr/testify/assert" ) @@ -23,9 +23,9 @@ func TestRuntimeConfig_DebugMode(t *testing.T) { t.Run(tc.debugEnv, func(t *testing.T) { t.Parallel() - pctx := portercontext.New() - pctx.Setenv("PORTER_DEBUG", tc.debugEnv) - c := NewConfigFor(pctx) + config := config.NewTestConfig(t) + config.Setenv("PORTER_DEBUG", tc.debugEnv) + c := NewConfigFor(config.Config) assert.Equal(t, tc.wantDebug, c.DebugMode) }) } diff --git a/pkg/runtime/helpers.go b/pkg/runtime/helpers.go index e1ff5a409..3095ae2ff 100644 --- a/pkg/runtime/helpers.go +++ b/pkg/runtime/helpers.go @@ -3,6 +3,7 @@ package runtime import ( "testing" + "get.porter.sh/porter/pkg/config" "get.porter.sh/porter/pkg/mixin" "get.porter.sh/porter/pkg/portercontext" ) @@ -13,15 +14,15 @@ type TestPorterRuntime struct { } func NewTestPorterRuntime(t *testing.T) *TestPorterRuntime { - cxt := portercontext.NewTestContext(t) - cxt.Setenv("PORTER_DEBUG", "true") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PORTER_DEBUG", "true") mixins := mixin.NewTestMixinProvider() - cfg := NewConfigFor(cxt.Context) + cfg := NewConfigFor(testConfig.Config) pr := NewPorterRuntime(cfg, mixins) return &TestPorterRuntime{ - TestContext: cxt, + TestContext: testConfig.TestContext, PorterRuntime: pr, } } @@ -32,11 +33,11 @@ type TestRuntimeConfig struct { } func NewTestRuntimeConfig(t *testing.T) TestRuntimeConfig { - porterCtx := portercontext.NewTestContext(t) - porterCtx.Setenv("PORTER_DEBUG", "true") - runtimeCfg := NewConfigFor(porterCtx.Context) + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PORTER_DEBUG", "true") + runtimeCfg := NewConfigFor(testConfig.Config) return TestRuntimeConfig{ RuntimeConfig: runtimeCfg, - TestContext: porterCtx, + TestContext: testConfig.TestContext, } } diff --git a/pkg/runtime/runtime_manifest.go b/pkg/runtime/runtime_manifest.go index a630023dc..4760b3410 100644 --- a/pkg/runtime/runtime_manifest.go +++ b/pkg/runtime/runtime_manifest.go @@ -16,6 +16,7 @@ import ( "get.porter.sh/porter/pkg" "get.porter.sh/porter/pkg/cnab" "get.porter.sh/porter/pkg/config" + "get.porter.sh/porter/pkg/experimental" "get.porter.sh/porter/pkg/manifest" "get.porter.sh/porter/pkg/tracing" "get.porter.sh/porter/pkg/yaml" @@ -417,6 +418,30 @@ func (m *RuntimeManifest) buildSourceData() (map[string]interface{}, error) { return data, nil } +func (m *RuntimeManifest) buildAndResolveMappedDependencyOutputs(sourceData map[string]interface{}) error { + for _, manifestDep := range m.Dependencies.Requires { + var depBun = sourceData["bundle"].(map[string]interface{})["dependencies"].(map[string]interface{})[manifestDep.Name].(map[string]interface{}) + var depOutputs map[string]interface{} + if depBun["outputs"] == nil { + depOutputs = make(map[string]interface{}) + depBun["outputs"] = depOutputs + } else { + depOutputs = depBun["outputs"].(map[string]interface{}) + } + + for outputName, mappedOutput := range manifestDep.Outputs { + mappedOutputTemplate := m.GetTemplatePrefix() + mappedOutput + renderedOutput, err := mustache.RenderRaw(mappedOutputTemplate, true, sourceData) + if err != nil { + return fmt.Errorf("unable to render dependency %s output template %s: %w", manifestDep.Name, mappedOutput, err) + } + depOutputs[outputName] = renderedOutput + } + } + + return nil +} + // ResolveStep will walk through the Step's data and resolve any placeholder // data using the definitions in the manifest, like parameters or credentials. func (m *RuntimeManifest) ResolveStep(ctx context.Context, stepIndex int, step *manifest.Step) error { @@ -428,6 +453,15 @@ func (m *RuntimeManifest) ResolveStep(ctx context.Context, stepIndex int, step * return log.Error(fmt.Errorf("unable to build step template data: %w", err)) } + mustache.AllowMissingVariables = false + + if m.config.IsFeatureEnabled(experimental.FlagDependenciesV2) { + err = m.buildAndResolveMappedDependencyOutputs(sourceData) + if err != nil { + return log.Errorf("unable to build and resolve mapped dependency outputs: %w", err) + } + } + // Get the original yaml for the current step stepPath := fmt.Sprintf("%s[%d]", m.Action, stepIndex) stepTemplate, err := m.getStepTemplate(stepPath) @@ -439,7 +473,6 @@ func (m *RuntimeManifest) ResolveStep(ctx context.Context, stepIndex int, step * //fmt.Fprintf(m.Err, "=== Step Data ===\n%v\n", sourceData) m.debugf(log, "=== Step Template ===\n%v\n", stepTemplate) - mustache.AllowMissingVariables = false rendered, err := mustache.RenderRaw(stepTemplate, true, sourceData) if err != nil { return log.Errorf("unable to render step template %s: %w", stepTemplate, err) diff --git a/pkg/runtime/runtime_manifest_test.go b/pkg/runtime/runtime_manifest_test.go index ca65ad9fb..f49924dc0 100644 --- a/pkg/runtime/runtime_manifest_test.go +++ b/pkg/runtime/runtime_manifest_test.go @@ -10,6 +10,7 @@ import ( "get.porter.sh/porter/pkg" "get.porter.sh/porter/pkg/cnab" "get.porter.sh/porter/pkg/config" + "get.porter.sh/porter/pkg/experimental" "get.porter.sh/porter/pkg/manifest" "get.porter.sh/porter/pkg/portercontext" "get.porter.sh/porter/tests" @@ -20,19 +21,19 @@ import ( "github.com/stretchr/testify/require" ) -func runtimeManifestFromStepYaml(t *testing.T, pCtx *portercontext.TestContext, stepYaml string) *RuntimeManifest { +func runtimeManifestFromStepYaml(t *testing.T, testConfig *config.TestConfig, stepYaml string) *RuntimeManifest { mContent := []byte(stepYaml) - require.NoError(t, pCtx.FileSystem.WriteFile("/cnab/app/porter.yaml", mContent, pkg.FileModeWritable)) - m, err := manifest.ReadManifest(pCtx.Context, "/cnab/app/porter.yaml") + require.NoError(t, testConfig.FileSystem.WriteFile("/cnab/app/porter.yaml", mContent, pkg.FileModeWritable)) + m, err := manifest.ReadManifest(testConfig.Context, "/cnab/app/porter.yaml") require.NoError(t, err, "ReadManifest failed") - cfg := NewConfigFor(pCtx.Context) + cfg := NewConfigFor(testConfig.Config) return NewRuntimeManifest(cfg, cnab.ActionInstall, m) } func TestResolveMapParam(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("PERSON", "Ralpha") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PERSON", "Ralpha") mContent := `schemaVersion: 1.0.0-alpha.2 parameters: @@ -45,7 +46,7 @@ install: Parameters: Thing: ${ bundle.parameters.person } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -66,8 +67,8 @@ install: } func TestStateBagUnpack(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("PERSON", "Ralpha") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PERSON", "Ralpha") mContent := `schemaVersion: 1.0.0-alpha.2 parameters: @@ -106,8 +107,8 @@ state: } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) - require.NoError(t, pCtx.FileSystem.WriteFile("/porter/state.tgz", []byte(test.stateContent), pkg.FileModeWritable)) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) + require.NoError(t, testConfig.FileSystem.WriteFile("/porter/state.tgz", []byte(test.stateContent), pkg.FileModeWritable)) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -119,14 +120,14 @@ state: } else { require.Contains(t, err.Error(), test.expErr.Error()) } - pCtx.FileSystem.Remove("/porter/state.tgz") + testConfig.FileSystem.Remove("/porter/state.tgz") }) } } func TestResolvePathParam(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0-alpha.2 parameters: @@ -138,7 +139,7 @@ install: Parameters: Thing: ${ bundle.parameters.person } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -161,7 +162,7 @@ func TestMetadataAvailableForTemplating(t *testing.T) { c.TestContext.AddTestFile("testdata/metadata-substitution.yaml", config.Name) m, err := manifest.LoadManifestFrom(context.Background(), c.Config, config.Name) require.NoError(t, err, "LoadManifestFrom") - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(c.Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) s := rm.Install[0] @@ -181,7 +182,7 @@ func TestDependencyMetadataAvailableForTemplating(t *testing.T) { m, err := manifest.LoadManifestFrom(context.Background(), c.Config, config.Name) require.NoError(t, err, "LoadManifestFrom") - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(c.Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) rm.bundles = map[string]cnab.ExtendedBundle{ "mysql": cnab.NewBundle(bundle.Bundle{ @@ -203,7 +204,7 @@ func TestDependencyMetadataAvailableForTemplating(t *testing.T) { func TestResolveMapParamUnknown(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0 install: @@ -211,7 +212,7 @@ install: Parameters: Thing: ${bundle.parameters.person} ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -221,7 +222,7 @@ install: func TestResolveArrayUnknown(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0 parameters: @@ -232,7 +233,7 @@ install: Arguments: - ${bundle.parameters.person} ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -242,8 +243,8 @@ install: func TestResolveArray(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("PERSON", "Ralpha") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PERSON", "Ralpha") mContent := `schemaVersion: 1.0.0 parameters: @@ -254,7 +255,7 @@ install: Arguments: - ${ bundle.parameters.person } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -270,9 +271,9 @@ install: func TestResolveSensitiveParameter(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("SENSITIVE_PARAM", "deliciou$dubonnet") - pCtx.Setenv("REGULAR_PARAM", "regular param value") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("SENSITIVE_PARAM", "deliciou$dubonnet") + testConfig.Setenv("REGULAR_PARAM", "regular param value") mContent := `schemaVersion: 1.0.0 parameters: @@ -286,7 +287,7 @@ install: - ${ bundle.parameters.sensitive_param } - ${ bundle.parameters.regular_param } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] // Prior to resolving step values, this method should return an empty string array @@ -310,8 +311,8 @@ install: func TestResolveCredential(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("PASSWORD", "deliciou$dubonnet") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PASSWORD", "deliciou$dubonnet") mContent := `schemaVersion: 1.0.0 credentials: @@ -323,7 +324,7 @@ install: Arguments: - ${ bundle.credentials.password } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] // Prior to resolving step values, this method should return an empty string array @@ -344,9 +345,9 @@ install: func TestResolveStep_DependencyOutput(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("PORTER_MYSQL_PASSWORD_DEP_OUTPUT", "password") - pCtx.Setenv("PORTER_MYSQL_ROOT_PASSWORD_DEP_OUTPUT", "mysql-password") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("PORTER_MYSQL_PASSWORD_DEP_OUTPUT", "password") + testConfig.Setenv("PORTER_MYSQL_ROOT_PASSWORD_DEP_OUTPUT", "mysql-password") mContent := `schemaVersion: 1.0.0 dependencies: @@ -361,7 +362,7 @@ install: - ${ bundle.dependencies.mysql.outputs.password } - ${ bundle.dependencies.mysql.outputs.root-password } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) ps := cnab.ParameterSources{} ps.SetParameterFromDependencyOutput("porter-mysql-password", "mysql", "password") ps.SetParameterFromDependencyOutput("porter-mysql-root-password", "mysql", "root-password") @@ -406,6 +407,97 @@ install: assert.Equal(t, []string{"mysql-password", "password"}, gotSensitiveValues, "Incorrect values were marked as sensitive") } +func TestResolveStep_DependencyMappedOutput(t *testing.T) { + ctx := context.Background() + testConfig := config.NewTestConfig(t) + testConfig.SetExperimentalFlags(experimental.FlagDependenciesV2) + + mContent := `schemaVersion: 1.0.0 +dependencies: + requires: + - name: mysql + bundle: + reference: "getporter/porter-mysql" + outputs: + mappedOutput: Mapped + +install: +- mymixin: + Arguments: + - ${ bundle.dependencies.mysql.outputs.mappedOutput } +` + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) + rm.bundles = map[string]cnab.ExtendedBundle{ + "mysql": cnab.NewBundle(bundle.Bundle{}), + } + + s := rm.Install[0] + err := rm.ResolveStep(ctx, 0, s) + require.NoError(t, err) + + require.IsType(t, map[string]interface{}{}, s.Data["mymixin"], "Data.mymixin has incorrect type") + mixin := s.Data["mymixin"].(map[string]interface{}) + require.IsType(t, mixin["Arguments"], []interface{}{}, "Data.mymixin.Arguments has incorrect type") + args := mixin["Arguments"].([]interface{}) + + assert.Equal(t, []interface{}{"Mapped"}, args, "Incorrect template args passed to the mixin step") +} + +func TestResolveStep_DependencyTemplatedMappedOutput(t *testing.T) { + ctx := context.Background() + testConfig := config.NewTestConfig(t) + testConfig.SetExperimentalFlags(experimental.FlagDependenciesV2) + testConfig.Setenv("PORTER_MYSQL_PASSWORD_DEP_OUTPUT", "password") + + mContent := `schemaVersion: 1.0.0 +dependencies: + requires: + - name: mysql + bundle: + reference: "getporter/porter-mysql" + outputs: + mappedOutput: ${ bundle.dependencies.mysql.outputs.password } + +install: +- mymixin: + Arguments: + - ${ bundle.dependencies.mysql.outputs.mappedOutput } +` + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) + ps := cnab.ParameterSources{} + ps.SetParameterFromDependencyOutput("porter-mysql-password", "mysql", "password") + rm.bundle = cnab.NewBundle(bundle.Bundle{ + Custom: map[string]interface{}{ + cnab.ParameterSourcesExtensionKey: ps, + }, + RequiredExtensions: []string{cnab.ParameterSourcesExtensionKey}, + }) + + rm.bundles = map[string]cnab.ExtendedBundle{ + "mysql": cnab.NewBundle(bundle.Bundle{ + Outputs: map[string]bundle.Output{ + "password": { + Definition: "password", + }, + }, + Definitions: map[string]*definition.Schema{ + "password": {WriteOnly: makeBoolPtr(true)}, + }, + }), + } + + s := rm.Install[0] + err := rm.ResolveStep(ctx, 0, s) + require.NoError(t, err) + + require.IsType(t, map[string]interface{}{}, s.Data["mymixin"], "Data.mymixin has incorrect type") + mixin := s.Data["mymixin"].(map[string]interface{}) + require.IsType(t, mixin["Arguments"], []interface{}{}, "Data.mymixin.Arguments has incorrect type") + args := mixin["Arguments"].([]interface{}) + + assert.Equal(t, []interface{}{"password"}, args, "Incorrect template args passed to the mixin step") +} + func TestResolveInMainDict(t *testing.T) { ctx := context.Background() c := config.NewTestConfig(t) @@ -415,7 +507,7 @@ func TestResolveInMainDict(t *testing.T) { m, err := manifest.LoadManifestFrom(context.Background(), c.Config, config.Name) require.NoError(t, err, "could not load manifest") - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(c.Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) installStep := rm.Install[0] @@ -442,7 +534,7 @@ func TestResolveSliceWithAMap(t *testing.T) { m, err := manifest.LoadManifestFrom(context.Background(), c.Config, config.Name) require.NoError(t, err, "could not load manifest") - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(c.Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) installStep := rm.Install[0] @@ -461,7 +553,7 @@ func TestResolveSliceWithAMap(t *testing.T) { func TestResolveMissingStepOutputs(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0 install: @@ -469,7 +561,7 @@ install: Arguments: - jdbc://${bundle.outputs.database_url}:${bundle.outputs.database_port} ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -478,7 +570,7 @@ install: func TestResolveSensitiveOutputs(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0 outputs: - name: username @@ -491,7 +583,7 @@ install: - ${ bundle.outputs.username } - ${ bundle.outputs.password } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) rm.outputs = map[string]string{ "username": "sally", "password": "top$ecret!", @@ -516,7 +608,7 @@ install: func TestManifest_ResolveBundleName(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0 name: mybuns @@ -525,7 +617,7 @@ install: Arguments: - ${ bundle.name } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -642,7 +734,7 @@ func TestManifest_ApplyStepOutputs(t *testing.T) { m, err := manifest.LoadManifestFrom(context.Background(), c.Config, config.Name) require.NoError(t, err, "could not load manifest") - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(c.Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) err = rm.ApplyStepOutputs(map[string]string{"name": "world"}) @@ -664,7 +756,7 @@ func TestManifest_ResolveImageMap(t *testing.T) { m, err := manifest.LoadManifestFrom(context.Background(), c.Config, config.Name) require.NoError(t, err, "could not load manifest") - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(c.Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) expectedImage, ok := m.ImageMap["something"] require.True(t, ok, "couldn't get expected image") @@ -698,7 +790,7 @@ func TestManifest_ResolveImageMap(t *testing.T) { func TestManifest_ResolveImageMapMissingKey(t *testing.T) { // Try to access an images entry that doesn't exist ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0-alpha.2 images: something: @@ -710,7 +802,7 @@ install: Arguments: - ${ bundle.images.notsomething.digest } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -829,7 +921,6 @@ func TestResolveImageErrors(t *testing.T) { } func TestResolveImageWithUpdatedBundle(t *testing.T) { - pCtx := portercontext.NewTestContext(t) m := &manifest.Manifest{ ImageMap: map[string]manifest.MappedImage{ "machine": manifest.MappedImage{ @@ -851,7 +942,7 @@ func TestResolveImageWithUpdatedBundle(t *testing.T) { reloMap := relocation.ImageRelocationMap{} - cfg := NewConfigFor(pCtx.Context) + cfg := NewConfigFor(config.NewTestConfig(t).Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) err := rm.ResolveImages(bun, reloMap) require.NoError(t, err) @@ -860,7 +951,6 @@ func TestResolveImageWithUpdatedBundle(t *testing.T) { } func TestResolveImageWithUpdatedMismatchedBundle(t *testing.T) { - pCtx := portercontext.NewTestContext(t) m := &manifest.Manifest{ ImageMap: map[string]manifest.MappedImage{ "machine": manifest.MappedImage{ @@ -882,7 +972,7 @@ func TestResolveImageWithUpdatedMismatchedBundle(t *testing.T) { reloMap := relocation.ImageRelocationMap{} - cfg := NewConfigFor(pCtx.Context) + cfg := NewConfigFor(config.NewTestConfig(t).Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) err := rm.ResolveImages(bun, reloMap) assert.Error(t, err) @@ -891,7 +981,6 @@ func TestResolveImageWithUpdatedMismatchedBundle(t *testing.T) { } func TestResolveImageWithRelo(t *testing.T) { - pCtx := portercontext.NewTestContext(t) m := &manifest.Manifest{ ImageMap: map[string]manifest.MappedImage{ "machine": manifest.MappedImage{ @@ -915,7 +1004,7 @@ func TestResolveImageWithRelo(t *testing.T) { "gabrtv/microservice@sha256:cca460afa270d4c527981ef9ca4989346c56cf9b20217dcea37df1ece8120687": "my.registry/microservice@sha256:cca460afa270d4c527981ef9ca4989346c56cf9b20217dcea37df1ece8120687", } - cfg := NewConfigFor(pCtx.Context) + cfg := NewConfigFor(config.NewTestConfig(t).Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) err := rm.ResolveImages(bun, reloMap) require.NoError(t, err) @@ -924,7 +1013,6 @@ func TestResolveImageWithRelo(t *testing.T) { } func TestResolveImageRelocationNoMatch(t *testing.T) { - pCtx := portercontext.NewTestContext(t) m := &manifest.Manifest{ ImageMap: map[string]manifest.MappedImage{ "machine": manifest.MappedImage{ @@ -948,7 +1036,7 @@ func TestResolveImageRelocationNoMatch(t *testing.T) { "deislabs/nogood:latest": "cnabio/ghost:latest", } - cfg := NewConfigFor(pCtx.Context) + cfg := NewConfigFor(config.NewTestConfig(t).Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) err := rm.ResolveImages(bun, reloMap) require.NoError(t, err) @@ -957,10 +1045,10 @@ func TestResolveImageRelocationNoMatch(t *testing.T) { func TestResolveStepEncoding(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) wantValue := `{"test":"value"}` - pCtx.Setenv("TEST", wantValue) + testConfig.Setenv("TEST", wantValue) mContent := `schemaVersion: 1.0.0 parameters: @@ -972,7 +1060,7 @@ install: Flags: c: '${bundle.parameters.test}' ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -988,9 +1076,9 @@ install: func TestResolveInstallation(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv(config.EnvPorterInstallationNamespace, "mynamespace") - pCtx.Setenv(config.EnvPorterInstallationName, "mybun") + testConfig := config.NewTestConfig(t) + testConfig.Setenv(config.EnvPorterInstallationNamespace, "mynamespace") + testConfig.Setenv(config.EnvPorterInstallationName, "mybun") mContent := `schemaVersion: 1.0.0 install: @@ -998,7 +1086,7 @@ install: ns: ${ installation.namespace } release: ${ installation.name } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -1013,7 +1101,7 @@ install: func TestResolveCustomMetadata(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) + testConfig := config.NewTestConfig(t) mContent := `schemaVersion: 1.0.0 custom: @@ -1028,7 +1116,7 @@ install: featureA: ${ bundle.custom.myApp.featureFlags.featureA } notabool: "${ bundle.custom.myApp.featureFlags.featureA }" ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -1047,9 +1135,9 @@ install: func TestResolveEnvironmentVariable(t *testing.T) { ctx := context.Background() - pCtx := portercontext.NewTestContext(t) - pCtx.Setenv("foo", "foo-value") - pCtx.Setenv("BAR", "bar-value") + testConfig := config.NewTestConfig(t) + testConfig.Setenv("foo", "foo-value") + testConfig.Setenv("BAR", "bar-value") mContent := `schemaVersion: 1.0.0 install: @@ -1057,7 +1145,7 @@ install: someInput: ${ env.foo } moreInput: ${ env.BAR } ` - rm := runtimeManifestFromStepYaml(t, pCtx, mContent) + rm := runtimeManifestFromStepYaml(t, testConfig, mContent) s := rm.Install[0] err := rm.ResolveStep(ctx, 0, s) @@ -1096,8 +1184,7 @@ func TestResolveInvocationImage(t *testing.T) { }, } - pCtx := portercontext.NewTestContext(t) - cfg := NewConfigFor(pCtx.Context) + cfg := NewConfigFor(config.NewTestConfig(t).Config) for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/runtime/runtime_test.go b/pkg/runtime/runtime_test.go index a7ed36032..f0e12d0dd 100644 --- a/pkg/runtime/runtime_test.go +++ b/pkg/runtime/runtime_test.go @@ -252,14 +252,13 @@ func TestRuntimeManifest_ApplyUnboundBundleOutputs_File(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - c := portercontext.NewTestContext(t) m := &manifest.Manifest{ Name: "mybun", Outputs: manifest.OutputDefinitions{ tc.def.Name: tc.def, }, } - cfg := NewConfigFor(c.Context) + cfg := NewConfigFor(config.NewTestConfig(t).Config) rm := NewRuntimeManifest(cfg, cnab.ActionInstall, m) rm.bundle = cnab.NewBundle(bundle.Bundle{ Definitions: map[string]*definition.Schema{