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