mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-08 18:36:48 +00:00
Some checks failed
CodeQL / Analyze (go) (push) Failing after 1m43s
Definition-Lint / definition-doc (push) Failing after 6m13s
E2E MultiCluster Test / detect-noop (push) Successful in 24s
E2E Test / detect-noop (push) Successful in 17s
Go / detect-noop (push) Successful in 21s
license / Check for unapproved licenses (push) Failing after 2m38s
Registry / publish-core-images (push) Failing after 40s
Unit-Test / detect-noop (push) Successful in 20s
E2E MultiCluster Test / e2e-multi-cluster-tests (v1.29) (push) Failing after 1m55s
E2E Test / e2e-tests (v1.29) (push) Failing after 1m18s
Go / staticcheck (push) Successful in 18m35s
Go / lint (push) Failing after 19m38s
Go / check-diff (push) Failing after 15m7s
Go / check-core-image-build (push) Failing after 3m45s
Go / check-cli-image-build (push) Failing after 2m23s
Unit-Test / unit-tests (push) Failing after 12m43s
Go / check-windows (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Failing after 48s
* feature: Add Semantic versioning to KubeVela Definitions Fixes https://github.com/kubevela/kubevela/issues/6435 Fixes https://github.com/kubevela/kubevela/issues/6534 Changes: - Adds an optional "Version" field for all Definition Specs. - Adds the following new validations to Webhooks for Definitions: - Validate the "Version" field follows Semantic versioning. - Dis-allow conflicting versioning fields ( Name annotation, Spec.Version) - Adds the following new validations to Webhooks for Application: - Dis-allow the use of both the "publishVersion" & "autoUpdate" annotations. - Enahnce "multiStageComponentApply" feature to support auto updates. Boy Scout Changes: - Fixes Plugin e2e tests broken by the fix for 6534. - Fixes the dryRun and livediff commands to respect the "-n" namespace flag. - Fixes the Application ValidationWebhook to respect the "-n" namespace flag. Co-authored-by: Rahul Kumar <35751394+bugbounce@users.noreply.github.com> Co-authored-by: Chaitanya Reddy <chaitanyareddy0702@gmail.com> Co-authored-by: Vibhor Chinda <vibhorchinda@gmail.com> Co-authored-by: Shivin Gopalani <gopalanishivin@gmail.com> Signed-off-by: kanchan-dhamane <74534570+kanchan-dhamane@users.noreply.github.com> * feature: Add KEP to define the proposal Signed-off-by: kanchan-dhamane <74534570+kanchan-dhamane@users.noreply.github.com> * fix: Rebase and fix merge conflicts Signed-off-by: kanchan-dhamane <74534570+kanchan-dhamane@users.noreply.github.com> * Fix: Adds unit test cases Signed-off-by: kanchan-dhamane <74534570+kanchan-dhamane@users.noreply.github.com> --------- Signed-off-by: kanchan-dhamane <74534570+kanchan-dhamane@users.noreply.github.com> Co-authored-by: bugbounce <35751394+bugbounce@users.noreply.github.com>
138 lines
3.2 KiB
Go
138 lines
3.2 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 utils
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"cuelang.org/go/cue/errors"
|
|
"github.com/crossplane/crossplane-runtime/pkg/test"
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestValidateCueTemplate(t *testing.T) {
|
|
cases := map[string]struct {
|
|
cueTemplate string
|
|
want error
|
|
}{
|
|
"normalCueTemp": {
|
|
cueTemplate: "name: 'name'",
|
|
want: nil,
|
|
},
|
|
"contextNouFoundCueTemp": {
|
|
cueTemplate: `
|
|
output: {
|
|
metadata: {
|
|
name: context.name
|
|
label: context.label
|
|
annotation: "default"
|
|
}
|
|
}`,
|
|
want: nil,
|
|
},
|
|
"inValidCueTemp": {
|
|
cueTemplate: `
|
|
output: {
|
|
metadata: {
|
|
name: context.name
|
|
label: context.label
|
|
annotation: "default"
|
|
},
|
|
hello: world
|
|
}`,
|
|
want: errors.New("output.hello: reference \"world\" not found"),
|
|
},
|
|
}
|
|
|
|
for caseName, cs := range cases {
|
|
t.Run(caseName, func(t *testing.T) {
|
|
err := ValidateCueTemplate(cs.cueTemplate)
|
|
if diff := cmp.Diff(cs.want, err, test.EquateErrors()); diff != "" {
|
|
t.Errorf("\n%s\nValidateCueTemplate: -want , +got \n%s\n", cs.want, diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateSemanticVersion(t *testing.T) {
|
|
cases := map[string]struct {
|
|
version string
|
|
want error
|
|
}{
|
|
"validVersion": {
|
|
version: "1.2.3",
|
|
want: nil,
|
|
},
|
|
"versionWithAlphabets": {
|
|
version: "1.2.3-alpha",
|
|
want: errors.New("Not a valid version"),
|
|
},
|
|
"invalidVersion": {
|
|
version: "1.2",
|
|
want: errors.New("Not a valid version"),
|
|
},
|
|
}
|
|
for caseName, cs := range cases {
|
|
t.Run(caseName, func(t *testing.T) {
|
|
err := ValidateSemanticVersion(cs.version)
|
|
if cs.want != nil {
|
|
assert.Equal(t, err.Error(), cs.want.Error())
|
|
} else {
|
|
assert.Equal(t, err, cs.want)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateMultipleDefVersionsNotPresent(t *testing.T) {
|
|
cases := map[string]struct {
|
|
version string
|
|
revisionName string
|
|
want error
|
|
}{
|
|
"versionPresent": {
|
|
version: "1.2.3",
|
|
revisionName: "",
|
|
want: nil,
|
|
},
|
|
"revisionNamePresent": {
|
|
version: "",
|
|
revisionName: "2.3",
|
|
want: nil,
|
|
},
|
|
"versionAndRevisionNamePresent": {
|
|
version: "1.2.3",
|
|
revisionName: "2.3",
|
|
want: fmt.Errorf("ComponentDefinition has both spec.version and revision name annotation. Only one can be present"),
|
|
},
|
|
}
|
|
for caseName, cs := range cases {
|
|
t.Run(caseName, func(t *testing.T) {
|
|
err := ValidateMultipleDefVersionsNotPresent(cs.version, cs.revisionName, "ComponentDefinition")
|
|
if cs.want != nil {
|
|
assert.Equal(t, err.Error(), cs.want.Error())
|
|
} else {
|
|
assert.Equal(t, err, cs.want)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|