mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-17 06:46:47 +00:00
* Feat: add if in workflow struct Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commite800ed3e98) * Feat: implement the if in workflow Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commite171fa9212) * Feat: support dependency and skip for suspend step Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit6c045dc593) * Fix: fix the rebase from sub steps Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitf6746e7d26) * Fix: fix the lint Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit9cb9887327) * Feat: support if in sub steps Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitc41ccfabb9) * Feat: add tests in application controller Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitb308d89912) * Fix: fix the lint Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit2c784b185a) * Test: add more tests in discover and custom Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit39f49fd901) * Lint: fix lint Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitf5149c859a) * Tests: add more tests in application controller Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit255f4014c2) * Fix: change failed after retries into reason Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitdfbba699c5) * Fix: fix the terminate cli Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit14192e1fb3) * fix lint Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitd1dd602cc8) * remove the terminate workflow to pkg and add feature gates Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitbf5c8d138a) * resolve comments Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit8a1b499f24) * nit fix Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commit784e5f5db3) * make finish condition more clear Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> (cherry picked from commitb4c1ca36b0) Co-authored-by: FogDong <dongtianxin.tx@alibaba-inc.com>
103 lines
2.7 KiB
Go
103 lines
2.7 KiB
Go
/*
|
|
Copyright 2021 The KubeVela Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package hooks
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/crossplane/crossplane-runtime/pkg/test"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
|
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
|
"github.com/oam-dev/kubevela/pkg/cue/model/value"
|
|
wfContext "github.com/oam-dev/kubevela/pkg/workflow/context"
|
|
)
|
|
|
|
func TestInput(t *testing.T) {
|
|
wfCtx := mockContext(t)
|
|
r := require.New(t)
|
|
paramValue, err := wfCtx.MakeParameter(map[string]interface{}{
|
|
"name": "foo",
|
|
})
|
|
r.NoError(err)
|
|
score, err := paramValue.MakeValue(`score: 99`)
|
|
r.NoError(err)
|
|
err = wfCtx.SetVar(score, "foo")
|
|
r.NoError(err)
|
|
err = Input(wfCtx, paramValue, v1beta1.WorkflowStep{
|
|
DependsOn: []string{"mystep"},
|
|
Inputs: common.StepInputs{{
|
|
From: "foo.score",
|
|
ParameterKey: "myscore",
|
|
}},
|
|
})
|
|
r.NoError(err)
|
|
result, err := paramValue.LookupValue("myscore")
|
|
r.NoError(err)
|
|
s, err := result.String()
|
|
r.NoError(err)
|
|
r.Equal(s, `99
|
|
`)
|
|
}
|
|
|
|
func TestOutput(t *testing.T) {
|
|
wfCtx := mockContext(t)
|
|
r := require.New(t)
|
|
taskValue, err := value.NewValue(`
|
|
output: score: 99
|
|
`, nil, "")
|
|
r.NoError(err)
|
|
err = Output(wfCtx, taskValue, v1beta1.WorkflowStep{
|
|
Properties: &runtime.RawExtension{
|
|
Raw: []byte("{\"name\":\"mystep\"}"),
|
|
},
|
|
Outputs: common.StepOutputs{{
|
|
ValueFrom: "output.score",
|
|
Name: "myscore",
|
|
}},
|
|
}, common.WorkflowStepPhaseSucceeded)
|
|
r.NoError(err)
|
|
result, err := wfCtx.GetVar("myscore")
|
|
r.NoError(err)
|
|
s, err := result.String()
|
|
r.NoError(err)
|
|
r.Equal(s, `99
|
|
`)
|
|
}
|
|
|
|
func mockContext(t *testing.T) wfContext.Context {
|
|
cli := &test.MockClient{
|
|
MockCreate: func(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
|
|
return nil
|
|
},
|
|
MockUpdate: func(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
|
|
return nil
|
|
},
|
|
MockGet: func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
|
|
return nil
|
|
},
|
|
}
|
|
wfCtx, err := wfContext.NewContext(cli, "default", "v1", "testuid")
|
|
require.NoError(t, err)
|
|
return wfCtx
|
|
}
|