kubekey/api/project/v1/conditional_test.go
liujian 86ff6371b6
Uninstall docker interface (#2478)
Signed-off-by: joyceliu <joyceliu@yunify.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
2025-03-05 18:55:12 +08:00

46 lines
732 B
Go

package v1
import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestUnmarshalWhen(t *testing.T) {
testcases := []struct {
name string
content string
except []string
}{
{
name: "test single string",
content: `
when: .a | eq "b"`,
except: []string{
".a | eq \"b\"",
},
},
{
name: "test multi string",
content: `
when:
- .a | eq "b"
- .b | ne "c"`,
except: []string{
".a | eq \"b\"",
".b | ne \"c\"",
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
var when Conditional
err := yaml.Unmarshal([]byte(tc.content), &when)
assert.NoError(t, err)
assert.Equal(t, tc.except, when.When.Data)
})
}
}