MCPcopy
hub / github.com/helm/helm / TestMetadataV1ValidateVersion

Function TestMetadataV1ValidateVersion

internal/plugin/metadata_v1_test.go:24–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestMetadataV1ValidateVersion(t *testing.T) {
25 base := func() MetadataV1 {
26 return MetadataV1{
27 APIVersion: "v1",
28 Name: "myplugin",
29 Type: "cli/v1",
30 Runtime: "subprocess",
31 Version: "1.0.0",
32 }
33 }
34
35 testsValid := map[string]string{
36 "simple version": "1.0.0",
37 "with prerelease": "1.2.3-alpha.1",
38 "with build meta": "1.2.3+build.123",
39 "full prerelease": "1.2.3-alpha.1+build.123",
40 }
41
42 for name, version := range testsValid {
43 t.Run("valid/"+name, func(t *testing.T) {
44 m := base()
45 m.Version = version
46 assert.NoError(t, m.Validate())
47 })
48 }
49
50 testsInvalid := map[string]struct {
51 version string
52 errMsg string
53 }{
54 "empty version": {
55 version: "",
56 errMsg: "plugin `version` is required",
57 },
58 "v prefix": {
59 version: "v1.0.0",
60 errMsg: "invalid plugin `version` \"v1.0.0\": must be valid semver",
61 },
62 "path traversal": {
63 version: "../../../../tmp/evil",
64 errMsg: "invalid plugin `version`",
65 },
66 "path traversal etc": {
67 version: "../../../etc/passwd",
68 errMsg: "invalid plugin `version`",
69 },
70 "not a version": {
71 version: "not-a-version",
72 errMsg: "invalid plugin `version`",
73 },
74 }
75
76 for name, tc := range testsInvalid {
77 t.Run("invalid/"+name, func(t *testing.T) {
78 m := base()
79 m.Version = tc.version
80 err := m.Validate()
81 assert.Error(t, err)

Callers

nothing calls this directly

Calls 5

baseStruct · 0.85
ContainsMethod · 0.80
RunMethod · 0.65
ValidateMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…