github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/fixtures/bugs/1232/discriminatedMarshalling_test.go (about)

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