github.com/youyuanwu/go-swagger@v0.19.0/cmd/swagger/commands/mixin_test.go (about) 1 package commands 2 3 import ( 4 "io/ioutil" 5 "log" 6 "os" 7 "path/filepath" 8 "testing" 9 10 flags "github.com/jessevdk/go-flags" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 var fixtureBase = filepath.FromSlash("../../../fixtures") 15 16 // Commands requires at least one arg 17 func TestCmd_Mixin(t *testing.T) { 18 log.SetOutput(ioutil.Discard) 19 defer log.SetOutput(os.Stdout) 20 21 v := MixinSpec{} 22 result := v.Execute([]string{}) 23 assert.Error(t, result) 24 25 result = v.Execute([]string{"nowhere.json"}) 26 assert.Error(t, result) 27 28 result = v.Execute([]string{"nowhere.json", "notThere.json"}) 29 assert.Error(t, result) 30 31 specDoc1 := filepath.Join(fixtureBase, "bugs", "1536", "fixture-1536.yaml") 32 result = v.Execute([]string{specDoc1, "notThere.json"}) 33 assert.Error(t, result) 34 } 35 36 func TestCmd_Mixin_NoError(t *testing.T) { 37 log.SetOutput(ioutil.Discard) 38 defer log.SetOutput(os.Stdout) 39 40 specDoc1 := filepath.Join(fixtureBase, "bugs", "1536", "fixture-1536.yaml") 41 specDoc2 := filepath.Join(fixtureBase, "bugs", "1536", "fixture-1536-2.yaml") 42 outDir, err := ioutil.TempDir(filepath.Dir(specDoc1), "mixed") 43 assert.NoError(t, err) 44 defer os.RemoveAll(outDir) 45 v := MixinSpec{ 46 ExpectedCollisionCount: 3, 47 Format: "yaml", 48 Output: flags.Filename(filepath.Join(outDir, "fixture-1536-mixed.yaml")), 49 } 50 51 result := v.Execute([]string{specDoc1, specDoc2}) 52 assert.NoError(t, result) 53 _, exists := os.Stat(filepath.Join(outDir, "fixture-1536-mixed.yaml")) 54 assert.True(t, !os.IsNotExist(exists)) 55 }