github.com/oam-dev/kubevela@v1.9.11/pkg/addon/reader_local_test.go (about) 1 /* 2 Copyright 2021 The KubeVela 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 addon 18 19 import ( 20 "strings" 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestLocalReader(t *testing.T) { 27 r := localReader{name: "local", dir: "./testdata/local"} 28 m, err := r.ListAddonMeta() 29 assert.NoError(t, err) 30 assert.Equal(t, len(m["local"].Items), 2) 31 32 file, err := r.ReadFile("metadata.yaml") 33 assert.NoError(t, err) 34 assert.Equal(t, file, metaFile) 35 36 file, err = r.ReadFile("resources/parameter.cue") 37 assert.NoError(t, err) 38 assert.Equal(t, true, strings.Contains(file, parameterFile)) 39 } 40 41 const ( 42 metaFile = `name: test-local-addon 43 version: 1.0.0 44 description: This is a addon for test when install addon from local 45 icon: https://www.terraform.io/assets/images/logo-text-8c3ba8a6.svg 46 url: https://terraform.io/ 47 48 tags: [] 49 50 deployTo: 51 control_plane: true 52 runtime_cluster: false 53 54 dependencies: [] 55 56 invisible: false` 57 58 parameterFile = `parameter: { 59 // test wrong parameter 60 example: *"default" 61 }` 62 )