-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_test.go
More file actions
61 lines (53 loc) · 1.55 KB
/
patch_test.go
File metadata and controls
61 lines (53 loc) · 1.55 KB
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
56
57
58
59
60
61
package main
import (
"encoding/json"
"testing"
"github.com/rtfpessoa/clitr/internal/patch"
"github.com/stretchr/testify/assert"
)
func TestFormatSuggestions_SingleField(t *testing.T) {
fields := []patch.UnknownField{
{
StructName: "TimelineEvent",
StructFile: "internal/types/event.go",
JSONKey: "newField",
RawValue: json.RawMessage(`"hello"`),
GoType: "string",
GoFieldName: "NewField",
},
}
output := formatSuggestions(fields)
assert.Contains(t, output, "Found 1 unknown field(s) across 1 struct(s):")
assert.Contains(t, output, "Struct: TimelineEvent (internal/types/event.go)")
assert.Contains(t, output, `+ NewField string`)
assert.Contains(t, output, `json:"newField,omitempty"`)
}
func TestFormatSuggestions_MultipleStructs(t *testing.T) {
fields := []patch.UnknownField{
{
StructName: "TimelineEvent",
StructFile: "internal/types/event.go",
JSONKey: "fieldA",
GoType: "string",
GoFieldName: "FieldA",
},
{
StructName: "Section",
StructFile: "internal/types/raw.go",
JSONKey: "fieldB",
GoType: "bool",
GoFieldName: "FieldB",
},
{
StructName: "TimelineEvent",
StructFile: "internal/types/event.go",
JSONKey: "fieldC",
GoType: "float64",
GoFieldName: "FieldC",
},
}
output := formatSuggestions(fields)
assert.Contains(t, output, "Found 3 unknown field(s) across 2 struct(s):")
assert.Contains(t, output, "Struct: Section (internal/types/raw.go)")
assert.Contains(t, output, "Struct: TimelineEvent (internal/types/event.go)")
}