github.com/oam-dev/kubevela@v1.9.11/pkg/builtin/build/build_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 build 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 24 "github.com/oam-dev/kubevela/pkg/builtin/registry" 25 cmdutil "github.com/oam-dev/kubevela/pkg/utils/util" 26 ) 27 28 func TestBuild(t *testing.T) { 29 errTestCase := []struct { 30 expectErr string 31 input map[string]interface{} 32 }{ 33 { 34 expectErr: "do task build: json: cannot unmarshal number into Go value of type build.Build", 35 input: map[string]interface{}{ 36 "build": 100, 37 }, 38 }, 39 { 40 expectErr: "do task build: json: cannot unmarshal string into Go value of type build.Build", 41 input: map[string]interface{}{ 42 "build": "test", 43 }, 44 }, 45 { 46 expectErr: "do task build: json: cannot unmarshal array into Go value of type build.Build", 47 input: map[string]interface{}{ 48 "build": []string{"test"}, 49 }, 50 }, 51 { 52 expectErr: "do task build: lookup field 'image' : not found", 53 input: map[string]interface{}{ 54 "build": map[string]interface{}{ 55 "docker": map[string]interface{}{ 56 "file": "./vela.yaml", 57 "context": "./docker", 58 }, 59 "push": map[string]interface{}{ 60 "Registry": "test.io", 61 }, 62 }, 63 }, 64 }, 65 { 66 expectErr: "do task build: image must be 'string'", 67 input: map[string]interface{}{ 68 "image": 1000, 69 "build": map[string]interface{}{ 70 "docker": map[string]interface{}{ 71 "file": "./vela.yaml", 72 "context": "./docker", 73 }, 74 "push": map[string]interface{}{ 75 "Registry": "test.io", 76 }, 77 }, 78 }, 79 }, 80 } 81 82 for _, tcase := range errTestCase { 83 _, err := registry.Run(tcase.input, cmdutil.IOStreams{}) 84 assert.Equal(t, err != nil, true) 85 assert.Equal(t, tcase.expectErr, err.Error()) 86 } 87 88 }