Skip to content

Commit

Permalink
Feat: add cue strategyUnify provider (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: yangsoon <[email protected]>
Co-authored-by: yangsoon <[email protected]>
  • Loading branch information
yangsoon and yangsoon authored Mar 30, 2023
1 parent d7022ea commit 10542b1
Show file tree
Hide file tree
Showing 11 changed files with 2,464 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cue/cuex/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/klog/v2"

"github.com/kubevela/pkg/cue/cuex/providers/base64"
cueext "github.com/kubevela/pkg/cue/cuex/providers/cue"
"github.com/kubevela/pkg/cue/cuex/providers/http"
"github.com/kubevela/pkg/cue/cuex/providers/kube"
cuexruntime "github.com/kubevela/pkg/cue/cuex/runtime"
Expand Down Expand Up @@ -217,6 +218,7 @@ func NewCompilerWithDefaultInternalPackages() *Compiler {
base64.Package,
http.Package,
kube.Package,
cueext.Package,
)
}

Expand Down
58 changes: 58 additions & 0 deletions cue/cuex/default_complier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cuex_test

import (
"context"

"cuelang.org/go/cue"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/kubevela/pkg/cue/cuex"
"github.com/kubevela/pkg/cue/cuex/model/sets"
"github.com/kubevela/pkg/util/stringtools"
)

var _ = Describe("Test Default Compiler", func() {
ctx := context.Background()
compiler := cuex.NewCompilerWithDefaultInternalPackages()

It("test vela/cue internal packages", func() {
val, err := compiler.CompileString(ctx, `
import (
"vela/cue"
)
secret: {
apiVersion: "v1"
kind: "Secret"
metadata: {
name: "ip"
namespace: "default"
}
}
patch: cue.#StrategyUnify & {
$params: {
value: secret
patch: {
stringData: ip: "127.0.0.1"
}
}
}
`)
Expect(err).Should(BeNil())
ret := val.LookupPath(cue.ParsePath("patch.$returns"))
retStr, err := sets.ToString(ret)
Expect(err).Should(BeNil())

Expect(stringtools.TrimLeadingIndent(retStr)).Should(BeEquivalentTo(stringtools.TrimLeadingIndent(`
apiVersion: "v1"
kind: "Secret"
stringData: {
ip: "127.0.0.1"
}
metadata: {
name: "ip"
namespace: "default"
}
`)))
})
})
Loading

0 comments on commit 10542b1

Please sign in to comment.