kubekey/pkg/modules/include_vars_test.go
zuoxuesong-worker a8e533e608
feature: support task include vars (#2717)
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>
2025-08-22 01:25:53 +00:00

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)
})
}
}