Merge "Implement render method for container exec"
This commit is contained in:
commit
1f5dbf8645
@ -170,8 +170,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"
|
||||
@ -289,6 +290,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