mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars feature: support task include vars Signed-off-by: xuesongzuo@yunify.com <xuesongzuo@yunify.com>
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package modules
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
)
|
|
|
|
func TestModuleIncludeVars(t *testing.T) {
|
|
testcases := []struct {
|
|
name string
|
|
opt ExecOptions
|
|
exceptStdout string
|
|
}{
|
|
{
|
|
name: "include remote path",
|
|
opt: ExecOptions{
|
|
Args: runtime.RawExtension{
|
|
Raw: []byte(`{
|
|
"include_vars": "http://127.0.0.1:8080/include_vars",
|
|
}`),
|
|
},
|
|
Variable: newTestVariable(nil, nil),
|
|
},
|
|
exceptStdout: StdoutFailed,
|
|
}, {
|
|
name: "include empty path",
|
|
opt: ExecOptions{
|
|
Args: runtime.RawExtension{
|
|
Raw: []byte(`{
|
|
"include_vars": "",
|
|
}`),
|
|
},
|
|
Variable: newTestVariable(nil, nil),
|
|
},
|
|
exceptStdout: StdoutFailed,
|
|
}, {
|
|
name: "include path not exist",
|
|
opt: ExecOptions{
|
|
Args: runtime.RawExtension{
|
|
Raw: []byte(`{
|
|
"include_vars": "/path/not/exist/not_exist.yaml",
|
|
}`),
|
|
},
|
|
Variable: newTestVariable(nil, nil),
|
|
},
|
|
exceptStdout: StdoutFailed,
|
|
}, {
|
|
name: "include path not yaml",
|
|
opt: ExecOptions{
|
|
Args: runtime.RawExtension{
|
|
Raw: []byte(`{
|
|
"include_vars": "/path/some/exist/exist.yyy",
|
|
}`),
|
|
},
|
|
Variable: newTestVariable(nil, nil),
|
|
},
|
|
exceptStdout: StdoutFailed,
|
|
},
|
|
}
|
|
|
|
for _, testcase := range testcases {
|
|
t.Run(testcase.name, func(t *testing.T) {
|
|
stdout, _, _ := ModuleIncludeVars(context.Background(), testcase.opt)
|
|
assert.Equal(t, testcase.exceptStdout, stdout)
|
|
})
|
|
}
|
|
}
|