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

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package main
     5  
     6  import (
     7  	"bytes"
     8  	"encoding/json"
     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/stretchr/testify/assert"
    17  	"github.com/thetreep/go-swagger/fixtures/bugs/1232/gen-fixture-1232/models"
    18  )
    19  
    20  // "github.com/thetreep/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(
    26  		cwd, func(path string, info os.FileInfo, err error) error {
    27  			fixture := info.Name()
    28  			if !info.IsDir() && strings.HasPrefix(fixture, base) {
    29  				// read fixture
    30  				buf, _ := os.ReadFile(fixture)
    31  				body := bytes.NewBuffer(buf)
    32  
    33  				t.Logf("Fixture: %s", string(buf))
    34  				// unmarshall into model
    35  				consumer := runtime.JSONConsumer()
    36  				model, err := models.UnmarshalPet(body, consumer)
    37  				if assert.NoError(t, err) {
    38  					err = model.Validate(strfmt.Default)
    39  					if err == nil {
    40  						t.Logf("Validation for %s returned: valid", fixture)
    41  
    42  					} else {
    43  						t.Logf("Validation for %s returned: invalid, with: %v", fixture, err)
    44  					}
    45  				}
    46  				resp, erm := json.MarshalIndent(model, "", "  ")
    47  				if assert.NoError(t, erm) {
    48  					t.Logf("Marshalled as: %s", string(resp))
    49  				}
    50  			}
    51  			return nil
    52  		},
    53  	)
    54  
    55  }