From dc60b1116cc810ad5c6cf909d7f3d40a0dd67b27 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Sun, 4 Apr 2021 21:16:44 -0500 Subject: [PATCH] Implement render method for container exec Currently it returns NotImplemented error, and that's not correct behavior. Since this kind of executor has the bundle inside, it should be properly rendered. Change-Id: I4c4e417b064236130b4349560fa3eb2615a0f824 Signed-off-by: Ruslan Aliev --- pkg/phase/executors/container.go | 8 +++-- pkg/phase/executors/container_test.go | 51 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/pkg/phase/executors/container.go b/pkg/phase/executors/container.go index 619c52e7b..89c8ae2cf 100644 --- a/pkg/phase/executors/container.go +++ b/pkg/phase/executors/container.go @@ -173,8 +173,12 @@ func (c *ContainerExecutor) Validate() error { } // Render executor documents -func (c *ContainerExecutor) Render(_ io.Writer, _ ifc.RenderOptions) error { - return commonerrors.ErrNotImplemented{} +func (c *ContainerExecutor) Render(w io.Writer, o ifc.RenderOptions) error { + bundle, err := c.ExecutorBundle.SelectBundle(o.FilterSelector) + if err != nil { + return err + } + return bundle.Write(w) } func (c *ContainerExecutor) setConfig() error { diff --git a/pkg/phase/executors/container_test.go b/pkg/phase/executors/container_test.go index 754a0d9a9..3dc1488c4 100644 --- a/pkg/phase/executors/container_test.go +++ b/pkg/phase/executors/container_test.go @@ -13,6 +13,7 @@ package executors_test import ( + "bytes" "fmt" "io" "testing" @@ -273,6 +274,56 @@ func TestSetKubeConfig(t *testing.T) { } } +func TestContainerRender(t *testing.T) { + testCases := []struct { + name string + bundleData []byte + opts ifc.RenderOptions + expectedErr error + expectedOut string + }{ + { + name: "empty bundle", + bundleData: []byte{}, + opts: ifc.RenderOptions{}, + expectedOut: "", + expectedErr: nil, + }, + { + name: "valid bundle", + bundleData: []byte(`apiVersion: unittest.org/v1alpha1 +kind: Test +metadata: + name: TestName`), + opts: ifc.RenderOptions{FilterSelector: document.NewSelector().ByKind("Test").ByName("TestName")}, + expectedOut: `--- +apiVersion: unittest.org/v1alpha1 +kind: Test +metadata: + name: TestName +... +`, + expectedErr: nil, + }, + } + + buf := &bytes.Buffer{} + for _, tc := range testCases { + tt := tc + t.Run(tt.name, func(t *testing.T) { + bundle, err := document.NewBundleFromBytes(tt.bundleData) + require.NoError(t, err) + e := executors.ContainerExecutor{ + ExecutorBundle: bundle, + } + err = e.Render(buf, tt.opts) + assert.Equal(t, tt.expectedErr, err) + assert.Equal(t, tt.expectedOut, buf.String()) + buf.Reset() + }) + } +} + type fakeKubeConfig struct { getFile func() (string, kubeconfig.Cleanup, error) }