github.com/replicatedhq/ship@v0.55.0/pkg/lifecycle/render/terraform/render_test.go (about) 1 package terraform 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/golang/mock/gomock" 8 "github.com/replicatedhq/libyaml" 9 "github.com/replicatedhq/ship/pkg/api" 10 "github.com/replicatedhq/ship/pkg/constants" 11 "github.com/replicatedhq/ship/pkg/lifecycle/render/root" 12 "github.com/replicatedhq/ship/pkg/test-mocks/inline" 13 "github.com/replicatedhq/ship/pkg/testing/logger" 14 "github.com/replicatedhq/ship/pkg/testing/matchers" 15 "github.com/spf13/afero" 16 "github.com/stretchr/testify/require" 17 ) 18 19 func TestRenderer(t *testing.T) { 20 tests := []struct { 21 name string 22 asset api.TerraformAsset 23 }{ 24 { 25 name: "empty", 26 asset: api.TerraformAsset{ 27 Inline: "some tf config", 28 }, 29 }, 30 } 31 for _, test := range tests { 32 t.Run(test.name, func(t *testing.T) { 33 req := require.New(t) 34 mc := gomock.NewController(t) 35 mockInline := inline.NewMockRenderer(mc) 36 37 renderer := &LocalRenderer{ 38 Logger: &logger.TestLogger{T: t}, 39 Inline: mockInline, 40 } 41 42 assetMatcher := &matchers.Is{ 43 Describe: "inline asset", 44 Test: func(v interface{}) bool { 45 asset, ok := v.(api.InlineAsset) 46 if !ok { 47 return false 48 } 49 return asset.Contents == test.asset.Inline 50 }, 51 } 52 53 rootFs := root.Fs{ 54 Afero: afero.Afero{ 55 Fs: afero.NewBasePathFs(afero.NewMemMapFs(), constants.InstallerPrefixPath), 56 }, 57 RootPath: constants.InstallerPrefixPath, 58 } 59 metadata := api.ReleaseMetadata{} 60 groups := []libyaml.ConfigGroup{} 61 templateContext := map[string]interface{}{} 62 63 mockInline.EXPECT().Execute( 64 rootFs, 65 assetMatcher, 66 metadata, 67 templateContext, 68 groups, 69 ).Return(func(ctx context.Context) error { return nil }) 70 71 err := renderer.Execute( 72 rootFs, 73 test.asset, 74 metadata, 75 templateContext, 76 groups, 77 )(context.Background()) 78 79 req.NoError(err) 80 }) 81 } 82 }