github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/fixtures/bugs/1232/pet_test.go (about) 1 //+build ignore 2 3 package main 4 5 import ( 6 "bytes" 7 "encoding/json" 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 "strings" 12 "testing" 13 14 "github.com/go-openapi/runtime" 15 "github.com/go-openapi/strfmt" 16 "github.com/go-swagger/go-swagger/fixtures/bugs/1232/gen-fixture-1232/models" 17 "github.com/stretchr/testify/assert" 18 ) 19 20 //"github.com/go-swagger/go-swagger/fixtures/bugs/1232/gen-fixture-1232/mode" 21 22 func Test_Pet(t *testing.T) { 23 base := "pet-data" 24 cwd, _ := os.Getwd() 25 filepath.Walk(cwd, func(path string, info os.FileInfo, err error) error { 26 fixture := info.Name() 27 if !info.IsDir() && strings.HasPrefix(fixture, base) { 28 // read fixture 29 buf, _ := ioutil.ReadFile(fixture) 30 body := bytes.NewBuffer(buf) 31 32 t.Logf("Fixture: %s", string(buf)) 33 // unmarshall into model 34 consumer := runtime.JSONConsumer() 35 model, err := models.UnmarshalPet(body, consumer) 36 if assert.NoError(t, err) { 37 err = model.Validate(strfmt.Default) 38 if err == nil { 39 t.Logf("Validation for %s returned: valid", fixture) 40 41 } else { 42 t.Logf("Validation for %s returned: invalid, with: %v", fixture, err) 43 } 44 } 45 resp, erm := json.MarshalIndent(model, "", " ") 46 if assert.NoError(t, erm) { 47 t.Logf("Marshalled as: %s", string(resp)) 48 } 49 } 50 return nil 51 }) 52 53 }