-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathserializer_test.go
55 lines (47 loc) · 1.44 KB
/
serializer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package internal_test
import (
"github.com/stretchr/testify/assert"
"testing"
conf "github.com/wal-g/wal-g/internal/config"
"github.com/spf13/viper"
"github.com/wal-g/wal-g/internal"
)
func TestDtoSerializer_NewDtoSerializer(t *testing.T) {
tests := []struct {
name string
serializerTypeSettingValue string
expectedDto internal.DtoSerializer
expectedErrText string
}{
{
name: "ReguralJSON_if_json_default",
serializerTypeSettingValue: "json_default",
expectedDto: internal.RegularJSON{},
expectedErrText: "",
},
{
name: "StreamedJSON_if_json_streamed",
serializerTypeSettingValue: "json_streamed",
expectedDto: internal.StreamedJSON{},
expectedErrText: "",
},
{
name: "error_if_unknown_type",
serializerTypeSettingValue: "ff",
expectedDto: nil,
expectedErrText: "undefined dto serializer type: ff",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viper.Set(conf.SerializerTypeSetting, tt.serializerTypeSettingValue)
dto, err := internal.NewDtoSerializer()
if tt.expectedErrText == "" {
assert.NoError(t, err)
} else {
assert.EqualError(t, err, tt.expectedErrText, "Errors not same")
}
assert.Equalf(t, tt.expectedDto, dto, "Expected different dto")
})
}
}