Files
kubevela/pkg/workflow/step/dependency_test.go
Amit Singh 5ead6db8d7
Some checks failed
Webhook Upgrade Validation / webhook-upgrade-check (push) Failing after 1m29s
Chore: bumps up pkg and workflow dependency versions (#7026)
* chore: bumps up workflow and pkg versions and updates import statements

Signed-off-by: Amit Singh <singhamitch@outlook.com>

* chore: minor linter fixes

Signed-off-by: Amit Singh <singhamitch@outlook.com>

---------

Signed-off-by: Amit Singh <singhamitch@outlook.com>
2026-01-20 15:32:03 +00:00

81 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 step
import (
"context"
"testing"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
wfTypesv1alpha1 "github.com/kubevela/pkg/apis/oam/v1alpha1"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/utils/common"
)
func TestLoadExternalPoliciesForWorkflow(t *testing.T) {
r := require.New(t)
cli := fake.NewClientBuilder().WithScheme(common.Scheme).WithObjects(&v1alpha1.Policy{
ObjectMeta: v1.ObjectMeta{
Name: "ex",
Namespace: "demo",
},
Type: "ex-type",
}).Build()
policies, err := LoadExternalPoliciesForWorkflow(context.Background(), cli, "demo", []wfTypesv1alpha1.WorkflowStep{{
WorkflowStepBase: wfTypesv1alpha1.WorkflowStepBase{
Name: "deploy",
Type: DeployWorkflowStep,
Properties: &runtime.RawExtension{Raw: []byte(`{"auto":false,"policies":["ex","internal"],"parallelism":10}`)},
},
}}, []v1beta1.AppPolicy{{
Name: "internal",
Type: "internal",
}})
r.NoError(err)
r.Equal(2, len(policies))
r.Equal("ex", policies[1].Name)
r.Equal("ex-type", policies[1].Type)
// Test policy not found
_, err = LoadExternalPoliciesForWorkflow(context.Background(), cli, "demo", []wfTypesv1alpha1.WorkflowStep{{
WorkflowStepBase: wfTypesv1alpha1.WorkflowStepBase{
Name: "deploy",
Type: DeployWorkflowStep,
Properties: &runtime.RawExtension{Raw: []byte(`{"policies":["ex","non"]}`)},
},
}}, []v1beta1.AppPolicy{})
r.NotNil(err)
r.Contains(err.Error(), "external policy non not found")
// Test invalid policy
_, err = LoadExternalPoliciesForWorkflow(context.Background(), cli, "demo", []wfTypesv1alpha1.WorkflowStep{{
WorkflowStepBase: wfTypesv1alpha1.WorkflowStepBase{
Name: "deploy",
Type: DeployWorkflowStep,
Properties: &runtime.RawExtension{Raw: []byte(`{"policies":["ex","non"],"unknown-field":"value"}`)},
},
}}, []v1beta1.AppPolicy{})
r.NotNil(err)
r.Contains(err.Error(), "invalid WorkflowStep deploy")
}