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 <raliev@mirantis.com>
This commit is contained in:
parent
346196e6c1
commit
dc60b1116c
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user