This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
forked from datacontract/datacontract-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff_test.go
204 lines (193 loc) Β· 6.41 KB
/
diff_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package datacontract
import (
"bytes"
"testing"
)
func TestDiff(t *testing.T) {
type args struct {
dataContractLocation string
stableDataContractLocation string
pathToModels []string
pathToType []string
pathToSpecification []string
}
tests := []LogOutputTest[args]{
{
name: "no model",
args: args{
dataContractLocation: "test_resources/diff/datacontract_no_model.yaml",
stableDataContractLocation: "test_resources/diff/datacontract_no_model.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 0 differences between the data contracts!
`,
},
{
name: "breaking - spec model",
args: args{
dataContractLocation: "test_resources/diff/breaking_datacontract.yaml",
stableDataContractLocation: "test_resources/diff/datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 2 differences between the data contracts!
π΄ Difference 1:
Description: field 'my_table.my_column' was removed
Type: field-removed
Severity: breaking
Level: field
InternalModel: my_table
InternalField: my_column
π‘ Difference 2:
Description: field 'my_table.my_column_2' was added
Type: field-added
Severity: info
Level: field
InternalModel: my_table
InternalField: my_column_2
`,
},
{
name: "not-breaking - spec model",
args: args{
dataContractLocation: "test_resources/diff/not_breaking_datacontract.yaml",
stableDataContractLocation: "test_resources/diff/datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 1 differences between the data contracts!
π‘ Difference 1:
Description: field 'my_table.my_column_2' was added
Type: field-added
Severity: info
Level: field
InternalModel: my_table
InternalField: my_column_2
`,
},
{
name: "two fields, 1 type-changed - spec model",
args: args{
dataContractLocation: "test_resources/diff/two_fields_datacontract.yaml",
stableDataContractLocation: "test_resources/diff/two_fields_stable_datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 1 differences between the data contracts!
π΄ Difference 1:
Description: type of field 'my_table.my_column' was changed from 'text' to 'timestamp'
Type: field-type-changed
Severity: breaking
Level: field
InternalModel: my_table
InternalField: my_column
`,
},
{
name: "breaking - dbt model",
args: args{
dataContractLocation: "test_resources/diff/dbt_breaking_datacontract.yaml",
stableDataContractLocation: "test_resources/diff/dbt_datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 2 differences between the data contracts!
π΄ Difference 1:
Description: field 'my_table.my_column' was removed
Type: field-removed
Severity: breaking
Level: field
InternalModel: my_table
InternalField: my_column
π‘ Difference 2:
Description: field 'my_table.my_column_2' was added
Type: field-added
Severity: info
Level: field
InternalModel: my_table
InternalField: my_column_2
`,
},
{
name: "not-breaking - dbt model",
args: args{
dataContractLocation: "test_resources/diff/dbt_not_breaking_datacontract.yaml",
stableDataContractLocation: "test_resources/diff/dbt_datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 1 differences between the data contracts!
π‘ Difference 1:
Description: field 'my_table.my_column_2' was added
Type: field-added
Severity: info
Level: field
InternalModel: my_table
InternalField: my_column_2
`,
},
{
name: "two fields, 1 type-changed - dbt model",
args: args{
dataContractLocation: "test_resources/diff/dbt_two_fields_datacontract.yaml",
stableDataContractLocation: "test_resources/diff/dbt_two_fields_stable_datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 1 differences between the data contracts!
π΄ Difference 1:
Description: type of field 'awesome_feature_usage_history.my_column' was changed from 'string' to 'timestamp'
Type: field-type-changed
Severity: breaking
Level: field
InternalModel: awesome_feature_usage_history
InternalField: my_column
`,
},
{
name: "spec model + dbt model",
args: args{
dataContractLocation: "test_resources/diff/datacontract.yaml",
stableDataContractLocation: "test_resources/diff/dbt_datacontract.yaml",
pathToModels: []string{"models"},
pathToType: []string{"schema", "type"},
pathToSpecification: []string{"schema", "specification"},
},
wantErr: false,
wantOutput: `Found 1 differences between the data contracts!
π‘ Difference 1:
Description: schema type changed from 'dbt' to 'data-contract-specification'
Type: dataset-schema-type-changed
Severity: info
Level: dataset
`,
},
}
for _, tt := range tests {
RunLogOutputTest(t, tt, "Diff", func(buffer *bytes.Buffer) error {
return Diff(
tt.args.dataContractLocation,
tt.args.stableDataContractLocation,
tt.args.pathToModels,
tt.args.pathToType,
tt.args.pathToSpecification,
buffer,
)
})
}
}