Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions fixtures/aerospike/aerospike.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"os"

"gopkg.in/yaml.v2"
"github.com/goccy/go-yaml"
)

type aerospikeClient interface {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (l *LoaderAerospike) loadYml(data []byte, ctx *loadContext) error {
return fmt.Errorf("unable to load template %s: duplicating ref name", name)
}

binMap, err := binMapFromYaml(template)
binMap, err := binMapFromValue(template)
if err != nil {
return err
}
Expand Down Expand Up @@ -172,15 +172,14 @@ func (l *LoaderAerospike) loadYml(data []byte, ctx *loadContext) error {
}

func setFromYaml(mapItem yaml.MapItem) (set, error) {
entries, ok := mapItem.Value.(yaml.MapSlice)
entries, ok := mapItem.Value.(map[string]interface{})
if !ok {
return nil, errors.New("expected map/array as set")
}

set := make(set, len(entries))
for _, e := range entries {
key := e.Key.(string)
binmap, err := binMapFromYaml(e)
for key, value := range entries {
binmap, err := binMapFromValue(value)
if err != nil {
return nil, err
}
Expand All @@ -190,15 +189,26 @@ func setFromYaml(mapItem yaml.MapItem) (set, error) {
return set, nil
}

func binMapFromYaml(mapItem yaml.MapItem) (binMap, error) {
bins, ok := mapItem.Value.(yaml.MapSlice)
if !ok {
func binMapFromValue(mapItemValue interface{}) (binMap, error) {
var bins map[string]interface{}

switch v := mapItemValue.(type) {
case map[string]interface{}:
bins = v
case yaml.MapItem:
value, ok := v.Value.(map[string]interface{})
if !ok {
return nil, errors.New("expected map/array as binmap")
}

bins = value
default:
return nil, errors.New("expected map/array as binmap")
}

binmap := make(binMap, len(bins))
for j := range bins {
binmap[bins[j].Key.(string)] = bins[j].Value
for k, v := range bins {
binmap[k] = v
}

return binmap, nil
Expand Down
6 changes: 3 additions & 3 deletions fixtures/aerospike/aerospike_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func TestLoaderAerospike_loadYml(t *testing.T) {
data: set{
"key1": {
"bin1": "value1",
"bin2": 1,
"bin2": uint64(1),
},
"key2": {
"bin1": "value2",
"bin2": 2,
"bin2": uint64(2),
"bin3": 2.569947773654566473,
},
},
Expand All @@ -52,7 +52,7 @@ func TestLoaderAerospike_loadYml(t *testing.T) {
},
"key2": {
"bin1": "'",
"bin5": []interface{}{1, "2"},
"bin5": []interface{}{uint64(1), "2"},
},
},
},
Expand Down
18 changes: 10 additions & 8 deletions fixtures/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strconv"
"strings"

"gopkg.in/yaml.v2"
"github.com/goccy/go-yaml"
)

type LoaderMysql struct {
Expand Down Expand Up @@ -129,11 +129,10 @@ func (l *LoaderMysql) loadYml(data []byte, ctx *loadContext) error {
return fmt.Errorf("unable to load template %s: duplicating ref name", name)
}

fields := template.Value.(yaml.MapSlice)
fields := template.Value.(map[string]interface{})
row := make(row, len(fields))
for _, field := range fields {
key := field.Key.(string)
row[key] = field.Value
for key, value := range fields {
row[key] = value
}

if base, ok := row["$extend"]; ok {
Expand Down Expand Up @@ -162,10 +161,10 @@ func (l *LoaderMysql) loadYml(data []byte, ctx *loadContext) error {
}
rows := make(table, len(sourceRows))
for i := range sourceRows {
sourceFields := sourceRows[i].(yaml.MapSlice)
sourceFields := sourceRows[i].(map[string]interface{})
fields := make(row, len(sourceFields))
for j := range sourceFields {
fields[sourceFields[j].Key.(string)] = sourceFields[j].Value
for k, v := range sourceFields {
fields[k] = v
}
rows[i] = fields
}
Expand Down Expand Up @@ -529,6 +528,9 @@ func toDbValue(value interface{}) (string, error) {
if value, ok := value.(int); ok {
return strconv.Itoa(value), nil
}
if value, ok := value.(uint64); ok {
return strconv.FormatUint(value, 10), nil
}
if value, ok := value.(float64); ok {
return strconv.FormatFloat(value, 'g', -1, 64), nil
}
Expand Down
18 changes: 10 additions & 8 deletions fixtures/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strconv"
"strings"

"gopkg.in/yaml.v2"
"github.com/goccy/go-yaml"
)

type LoaderPostgres struct {
Expand Down Expand Up @@ -150,11 +150,10 @@ func (f *LoaderPostgres) loadYml(data []byte, ctx *loadContext) error {
if _, ok := ctx.refsDefinition[name]; ok {
return fmt.Errorf("unable to load template %s: duplicating ref name", name)
}
fields := template.Value.(yaml.MapSlice)
fields := template.Value.(map[string]interface{})
row := make(row, len(fields))
for _, field := range fields {
key := field.Key.(string)
row[key] = field.Value
for key, field := range fields {
row[key] = field
}
if base, ok := row["$extend"]; ok {
base := base.(string)
Expand Down Expand Up @@ -189,10 +188,10 @@ func (f *LoaderPostgres) loadYml(data []byte, ctx *loadContext) error {
}
rows := make(table, len(sourceRows))
for i := range sourceRows {
sourceFields := sourceRows[i].(yaml.MapSlice)
sourceFields := sourceRows[i].(map[string]interface{})
fields := make(row, len(sourceFields))
for j := range sourceFields {
fields[sourceFields[j].Key.(string)] = sourceFields[j].Value
for key, value := range sourceFields {
fields[key] = value
}
rows[i] = fields
}
Expand Down Expand Up @@ -514,6 +513,9 @@ func toDbValue(value interface{}) (string, error) {
if value, ok := value.(int); ok {
return strconv.Itoa(value), nil
}
if value, ok := value.(uint64); ok {
return strconv.FormatUint(value, 10), nil
}
if value, ok := value.(float64); ok {
return strconv.FormatFloat(value, 'g', -1, 64), nil
}
Expand Down
4 changes: 4 additions & 0 deletions fixtures/redis/parser/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (obj *Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
case float64:
obj.Type = TypeFloat
obj.Value = v
//nolint:gosec // TODO: need correct implementation (after change yaml lib)
case uint64:
obj.Type = TypeInt
obj.Value = int(v)
default:
return fmt.Errorf("unknown value type: %T", v)
}
Expand Down
8 changes: 4 additions & 4 deletions fixtures/redis/parser/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"gopkg.in/yaml.v3"
"github.com/goccy/go-yaml"
)

type redisYamlParser struct {
Expand Down Expand Up @@ -473,19 +473,19 @@ func (p *redisYamlParser) Parse(ctx *Context, filename string) (*Fixture, error)

var fixture Fixture
if err := yaml.Unmarshal(data, &fixture); err != nil {
return nil, err
return nil, fmt.Errorf("yaml unmarshal: %w", err)
}

for _, parentFixture := range fixture.Inherits {
_, err := p.fileParser.ParseFiles(ctx, []string{parentFixture})
if err != nil {
return nil, err
return nil, fmt.Errorf("parse files: %w", err)
}
}

err = p.buildTemplate(ctx, fixture)
if err != nil {
return nil, err
return nil, fmt.Errorf("build template: %w", err)
}

for _, databaseData := range fixture.Databases {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.24.0
require (
github.com/aerospike/aerospike-client-go/v5 v5.11.0
github.com/fatih/color v1.18.0
github.com/goccy/go-yaml v1.19.0
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/kylelemons/godebug v1.1.0
Expand All @@ -14,8 +15,6 @@ require (
github.com/tidwall/gjson v1.18.0
golang.org/x/sync v0.19.0
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand All @@ -29,4 +28,5 @@ require (
github.com/tidwall/pretty v1.2.1 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
golang.org/x/sys v0.39.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/goccy/go-yaml v1.19.0 h1:EmkZ9RIsX+Uq4DYFowegAuJo8+xdX3T/2dwNPXbxEYE=
github.com/goccy/go-yaml v1.19.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
Expand Down
Loading
Loading