github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/tools/gen_test.go (about) 1 /* 2 Copyright 2018 Mirantis 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 tools 18 19 import ( 20 "bytes" 21 "strings" 22 "testing" 23 24 "github.com/Mirantis/virtlet/tests/gm" 25 ) 26 27 func TestGenCommand(t *testing.T) { 28 for _, tc := range []struct { 29 name string 30 args string 31 }{ 32 { 33 name: "plain", 34 args: "", 35 }, 36 { 37 name: "dev", 38 args: "--dev", 39 }, 40 { 41 name: "compat", 42 args: "--compat", 43 }, 44 { 45 name: "compat dev", 46 args: "--compat --dev", 47 }, 48 { 49 name: "tag", 50 args: "--tag 0.9.42", 51 }, 52 { 53 name: "crd", 54 args: "--crd", 55 }, 56 } { 57 t.Run(tc.name, func(t *testing.T) { 58 var out bytes.Buffer 59 cmd := NewGenCmd(&out) 60 if tc.args != "" { 61 cmd.SetArgs(strings.Split(tc.args, " ")) 62 } 63 cmd.SilenceUsage = true 64 cmd.SilenceErrors = true 65 if err := cmd.Execute(); err != nil { 66 t.Errorf("command failed: %q: %v", tc.args, err) 67 } else { 68 gm.Verify(t, gm.NewYamlVerifier(out.Bytes())) 69 } 70 }) 71 } 72 }