-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from ikramanop/feature/ignore-db-ordering
New: ignore db ordering in dbResponse feature
- Loading branch information
Showing
7 changed files
with
224 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package response_db | ||
|
||
import "testing" | ||
|
||
func TestCompareDbRespWithoutOrdering(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expected []string | ||
actual []string | ||
fail bool | ||
}{ | ||
{ | ||
name: "one line", | ||
expected: []string{"{ \"name\": \"John\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }"}, | ||
fail: false, | ||
}, | ||
{ | ||
name: "two lines", | ||
expected: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
fail: false, | ||
}, | ||
{ | ||
name: "two lines; different order", | ||
expected: []string{"{ \"surname\": \"Doe\" }", "{ \"name\": \"John\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
fail: false, | ||
}, | ||
{ | ||
name: "error", | ||
expected: []string{"{ \"name\": \"Jane\" }", "{ \"surname\": \"Doe\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
fail: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
errors, err := compareDbRespWithoutOrdering(tt.expected, tt.actual, tt.name) | ||
if tt.fail { | ||
if err == nil && len(errors) == 0 { | ||
t.Errorf("expected errors") | ||
} | ||
} else { | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if len(errors) > 0 { | ||
t.Errorf("got errors") | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestCompareDbResp(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
expected []string | ||
actual []string | ||
fail bool | ||
}{ | ||
{ | ||
name: "one line", | ||
expected: []string{"{ \"name\": \"John\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }"}, | ||
fail: false, | ||
}, | ||
{ | ||
name: "two lines", | ||
expected: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
fail: false, | ||
}, | ||
{ | ||
name: "two lines; different order", | ||
expected: []string{"{ \"surname\": \"Doe\" }", "{ \"name\": \"John\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
fail: true, | ||
}, | ||
{ | ||
name: "error", | ||
expected: []string{"{ \"name\": \"Jane\" }", "{ \"surname\": \"Doe\" }"}, | ||
actual: []string{"{ \"name\": \"John\" }", "{ \"surname\": \"Doe\" }"}, | ||
fail: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
errors, err := compareDbResp(tt.expected, tt.actual, tt.name, "") | ||
if tt.fail { | ||
if err == nil && len(errors) == 0 { | ||
t.Errorf("expected errors") | ||
} | ||
} else { | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if len(errors) > 0 { | ||
t.Errorf("got errors") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters