github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/cmd/swagger/commands/generate/support_test.go (about) 1 package generate_test 2 3 import ( 4 "io" 5 "log" 6 "os" 7 "path/filepath" 8 "testing" 9 10 flags "github.com/jessevdk/go-flags" 11 "github.com/thetreep/go-swagger/cmd/swagger/commands/generate" 12 ) 13 14 func TestGenerateSupport(t *testing.T) { 15 testGenerateSupport(t, false) 16 } 17 18 func TestGenerateSupportStrict(t *testing.T) { 19 testGenerateSupport(t, true) 20 } 21 22 func testGenerateSupport(t *testing.T, strict bool) { 23 specs := []string{ 24 "tasklist.basic.yml", 25 } 26 log.SetOutput(io.Discard) 27 defer log.SetOutput(os.Stdout) 28 29 base := filepath.FromSlash("../../../../") 30 for i, spec := range specs { 31 _ = t.Run( 32 spec, func(t *testing.T) { 33 path := filepath.Join(base, "fixtures/codegen", spec) 34 generated, err := os.MkdirTemp(filepath.Dir(path), "generated") 35 if err != nil { 36 t.Fatalf("TempDir()=%s", generated) 37 } 38 defer func() { 39 _ = os.RemoveAll(generated) 40 }() 41 m := &generate.Support{} 42 if i == 0 { 43 m.Shared.CopyrightFile = flags.Filename(filepath.Join(base, "LICENSE")) 44 } 45 _, _ = flags.Parse(m) 46 m.Shared.Spec = flags.Filename(path) 47 m.Shared.Target = flags.Filename(generated) 48 m.Shared.StrictResponders = strict 49 50 if err := m.Execute([]string{}); err != nil { 51 t.Error(err) 52 } 53 }, 54 ) 55 } 56 }