mirror of
https://github.com/jimeh/go-golden.git
synced 2026-02-19 11:16:47 +00:00
Tests have started using github.com/jimeh/go-mocktesting which allows testing unhappy paths where t.Fatal() and related functions are called.
99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
package golden
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jimeh/go-golden/marshal"
|
|
"github.com/jimeh/go-golden/unmarshal"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewMarshalingAsserter(t *testing.T) {
|
|
type args struct {
|
|
golden Golden
|
|
format string
|
|
marshalFunc MarshalFunc
|
|
unmarshalFunc UnmarshalFunc
|
|
normalizeLineBreaks bool
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *MarshalingAsserter
|
|
}{
|
|
{
|
|
name: "json",
|
|
args: args{
|
|
nil,
|
|
"JSON",
|
|
marshal.JSON,
|
|
unmarshal.JSON,
|
|
true,
|
|
},
|
|
want: &MarshalingAsserter{
|
|
Golden: nil,
|
|
Format: "JSON",
|
|
GoldName: "marshaled_json",
|
|
MarshalFunc: marshal.JSON,
|
|
UnmarshalFunc: unmarshal.JSON,
|
|
NormalizeLineBreaks: true,
|
|
},
|
|
},
|
|
{
|
|
name: "xml",
|
|
args: args{
|
|
nil,
|
|
"XML",
|
|
marshal.XML,
|
|
unmarshal.XML,
|
|
true,
|
|
},
|
|
want: &MarshalingAsserter{
|
|
Golden: nil,
|
|
Format: "XML",
|
|
GoldName: "marshaled_xml",
|
|
MarshalFunc: marshal.XML,
|
|
UnmarshalFunc: unmarshal.XML,
|
|
NormalizeLineBreaks: true,
|
|
},
|
|
},
|
|
{
|
|
name: "yaml",
|
|
args: args{
|
|
nil,
|
|
"YAML",
|
|
marshal.YAML,
|
|
unmarshal.YAML,
|
|
true,
|
|
},
|
|
want: &MarshalingAsserter{
|
|
Golden: nil,
|
|
Format: "YAML",
|
|
GoldName: "marshaled_yaml",
|
|
MarshalFunc: marshal.YAML,
|
|
UnmarshalFunc: unmarshal.YAML,
|
|
NormalizeLineBreaks: true,
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := NewMarshalingAsserter(
|
|
tt.args.golden,
|
|
tt.args.format,
|
|
tt.args.marshalFunc,
|
|
tt.args.unmarshalFunc,
|
|
tt.args.normalizeLineBreaks,
|
|
)
|
|
|
|
assert.Equal(t, tt.want.Golden, got.Golden)
|
|
assert.Equal(t, tt.want.Format, got.Format)
|
|
assert.Equal(t, tt.want.GoldName, got.GoldName)
|
|
assert.Equal(t,
|
|
tt.want.NormalizeLineBreaks,
|
|
got.NormalizeLineBreaks,
|
|
)
|
|
})
|
|
}
|
|
}
|