github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/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  	"github.com/go-swagger/go-swagger/cmd/swagger/commands/generate"
    11  	flags "github.com/jessevdk/go-flags"
    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(spec, func(t *testing.T) {
    32  			path := filepath.Join(base, "fixtures/codegen", spec)
    33  			generated, err := os.MkdirTemp(filepath.Dir(path), "generated")
    34  			if err != nil {
    35  				t.Fatalf("TempDir()=%s", generated)
    36  			}
    37  			defer func() {
    38  				_ = os.RemoveAll(generated)
    39  			}()
    40  			m := &generate.Support{}
    41  			if i == 0 {
    42  				m.Shared.CopyrightFile = flags.Filename(filepath.Join(base, "LICENSE"))
    43  			}
    44  			_, _ = flags.Parse(m)
    45  			m.Shared.Spec = flags.Filename(path)
    46  			m.Shared.Target = flags.Filename(generated)
    47  			m.Shared.StrictResponders = strict
    48  
    49  			if err := m.Execute([]string{}); err != nil {
    50  				t.Error(err)
    51  			}
    52  		})
    53  	}
    54  }