istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/config/file/store_test.go (about) 1 /* 2 Copyright Istio 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 file 18 19 import ( 20 "fmt" 21 "testing" 22 23 . "github.com/onsi/gomega" 24 25 "istio.io/istio/pkg/config/schema/collections" 26 "istio.io/istio/pkg/config/schema/gvk" 27 ) 28 29 func TestUpdateExistingContents(t *testing.T) { 30 g := NewWithT(t) 31 src := NewKubeSource(collections.Istio) 32 33 applyAndValidate := func(version string) { 34 configTemplate := `apiVersion: networking.istio.io/v1beta1 35 kind: DestinationRule 36 metadata: 37 name: productpage 38 labels: 39 version: %s 40 spec: 41 host: productpage 42 trafficPolicy: 43 tls: 44 mode: ISTIO_MUTUAL 45 subsets: 46 - name: %s 47 labels: 48 version: %s` 49 config := fmt.Sprintf(configTemplate, version, version, version) 50 err := src.ApplyContent("test", config) 51 g.Expect(err).To(BeNil()) 52 existing := src.Get(gvk.DestinationRule, "productpage", "") 53 g.Expect(existing.Labels["version"]).To(Equal(version)) 54 } 55 56 // Apply v1 config 57 applyAndValidate("v1") 58 // Apply v2 config and validate overwrite 59 applyAndValidate("v2") 60 }