github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/deploy/helm/parse_test.go (about) 1 /* 2 Copyright 2020 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package helm 18 19 import ( 20 "bufio" 21 "bytes" 22 "testing" 23 24 "github.com/google/go-cmp/cmp/cmpopts" 25 26 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/types" 27 "github.com/GoogleContainerTools/skaffold/testutil" 28 ) 29 30 func TestParseReleaseManifests(t *testing.T) { 31 tests := []struct { 32 description string 33 yaml []byte 34 expected []types.Artifact 35 }{ 36 { 37 description: "parse valid release info yaml with single artifact with namespace", 38 yaml: []byte(`# Source: skaffold-helm/templates/service.yaml 39 apiVersion: v1 40 kind: Service 41 metadata: 42 name: skaffold-helm-skaffold-helm 43 namespace: test 44 labels: 45 app: skaffold-helm 46 chart: skaffold-helm-0.1.0 47 release: skaffold-helm 48 heritage: Tiller 49 spec: 50 type: ClusterIP 51 ports: 52 - port: 80 53 targetPort: 80 54 protocol: TCP 55 name: nginx 56 selector: 57 app: skaffold-helm 58 release: skaffold-helm`), 59 expected: []types.Artifact{{Namespace: "test"}}, 60 }, 61 { 62 description: "parse valid release info yaml with single artifact without namespace sets helm namespace", 63 yaml: []byte(`# Source: skaffold-helm/templates/service.yaml 64 apiVersion: v1 65 kind: Service 66 metadata: 67 name: skaffold-helm-skaffold-helm 68 labels: 69 app: skaffold-helm 70 chart: skaffold-helm-0.1.0 71 release: skaffold-helm 72 heritage: Tiller 73 spec: 74 type: ClusterIP 75 ports: 76 - port: 80 77 targetPort: 80 78 protocol: TCP 79 name: nginx 80 selector: 81 app: skaffold-helm 82 release: skaffold-helm`), 83 expected: []types.Artifact{{ 84 Namespace: "testNamespace", 85 }}, 86 }, 87 { 88 description: "parse valid release info yaml with multiple artifacts", 89 yaml: []byte(`# Source: skaffold-helm/templates/service.yaml 90 apiVersion: v1 91 kind: Service 92 metadata: 93 name: skaffold-helm-skaffold-helm 94 labels: 95 app: skaffold-helm 96 chart: skaffold-helm-0.1.0 97 release: skaffold-helm 98 heritage: Tiller 99 spec: 100 type: ClusterIP 101 ports: 102 - port: 80 103 targetPort: 80 104 protocol: TCP 105 name: nginx 106 selector: 107 app: skaffold-helm 108 release: skaffold-helm 109 --- 110 # Source: skaffold-helm/templates/ingress.yaml 111 apiVersion: extensions/v1beta1 112 kind: Ingress 113 metadata: 114 name: skaffold-helm-skaffold-helm 115 namespace: test 116 labels: 117 app: skaffold-helm 118 chart: skaffold-helm-0.1.0 119 release: skaffold-helm 120 heritage: Tiller 121 annotations: 122 spec: 123 rules: 124 - http: 125 paths: 126 - path: / 127 backend: 128 serviceName: skaffold-helm-skaffold-helm 129 servicePort: 80`), 130 expected: []types.Artifact{{Namespace: "testNamespace"}, {Namespace: "test"}}, 131 }, 132 { 133 description: "parse invalid release info yaml", 134 yaml: []byte(`invalid release info`), 135 expected: nil, 136 }, 137 } 138 for _, test := range tests { 139 testutil.Run(t, test.description, func(t *testutil.T) { 140 r := bufio.NewReader(bytes.NewBuffer(test.yaml)) 141 142 actual := parseReleaseManifests("testNamespace", r) 143 144 t.CheckDeepEqual(test.expected, actual, cmpopts.IgnoreFields(types.Artifact{}, "Obj")) 145 }) 146 } 147 }