Skip to content

Commit

Permalink
add Passed field to TestOutput to track test success/failure (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
elh authored Feb 7, 2022
1 parent cdbf060 commit 8bd7ea3
Show file tree
Hide file tree
Showing 90 changed files with 98 additions and 8 deletions.
14 changes: 8 additions & 6 deletions dbtest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func TestGet(t *testing.T, oldValue, newValue Value, dbFn func(kvs []*VersionedK
t.Run(fmt.Sprintf("%v: %v", s.fixtures.name, tC.desc), func(t *testing.T) {
db, closeFn, err := dbFn(s.fixtures.vKVs())
defer closeFn()
defer WriteOutputHistory(db, []string{"A"}, t.Name())
defer WriteOutputHistory(t, db, []string{"A"}, t.Name())
require.Nil(t, err)
ret, err := db.Get(tC.key, tC.readOpts...)
if tC.expectErrNotFound {
Expand Down Expand Up @@ -449,7 +449,7 @@ func TestList(t *testing.T, oldValue, newValue Value, dbFn func(kvs []*Versioned
t.Run(fmt.Sprintf("%v: %v", s.fixtures.name, tC.desc), func(t *testing.T) {
db, closeFn, err := dbFn(s.fixtures.vKVs())
defer closeFn()
defer WriteOutputHistory(db, []string{"A"}, t.Name())
defer WriteOutputHistory(t, db, []string{"A"}, t.Name())
require.Nil(t, err)
ret, err := db.List(tC.readOpts...)
if tC.expectErr {
Expand Down Expand Up @@ -921,7 +921,7 @@ func TestSet(t *testing.T, dbFn func(kvs []*VersionedKV, clock Clock) (DB, error
t.Run(fmt.Sprintf("%v: %v", s.fixtures.name, tC.desc), func(t *testing.T) {
clock := &TestClock{}
db, err := dbFn(s.fixtures.vKVs(), clock)
defer WriteOutputHistory(db, []string{"A"}, t.Name())
defer WriteOutputHistory(t, db, []string{"A"}, t.Name())
require.Nil(t, err)
if tC.now != nil {
require.Nil(t, clock.SetNow(*tC.now))
Expand Down Expand Up @@ -1260,7 +1260,7 @@ func TestDelete(t *testing.T, oldValue, newValue Value, dbFn func(kvs []*Version
clock := &TestClock{}
db, closeFn, err := dbFn(s.fixtures.vKVs(), clock)
defer closeFn()
defer WriteOutputHistory(db, []string{"A"}, t.Name())
defer WriteOutputHistory(t, db, []string{"A"}, t.Name())
require.Nil(t, err)
if tC.now != nil {
require.Nil(t, clock.SetNow(*tC.now))
Expand Down Expand Up @@ -1615,7 +1615,7 @@ func TestHistory(t *testing.T, oldValue, newValue Value, dbFn func(kvs []*Versio
t.Run(fmt.Sprintf("%v: %v", s.fixtures.name, tC.desc), func(t *testing.T) {
db, closeFn, err := dbFn(s.fixtures.vKVs())
defer closeFn()
defer WriteOutputHistory(db, []string{"A"}, t.Name())
defer WriteOutputHistory(t, db, []string{"A"}, t.Name())
require.Nil(t, err)
ret, err := db.History(tC.key)
if tC.expectErrNotFound {
Expand Down Expand Up @@ -1651,12 +1651,13 @@ func toJSON(v interface{}) string {
// TestOutput is the format for saving test data for debugging and visualization.
type TestOutput struct {
TestName string
Passed bool // true is test passed
Histories map[string][]*VersionedKV // key -> history
}

// WriteOutputHistory writes to a file the final "history" for specified keys at the end of a test. This is used for
// debugging and visualization.
func WriteOutputHistory(db DB, keys []string, testName string) {
func WriteOutputHistory(t *testing.T, db DB, keys []string, testName string) {
if !outputHistory {
return
}
Expand All @@ -1674,6 +1675,7 @@ func WriteOutputHistory(db DB, keys []string, testName string) {
}
o := TestOutput{
TestName: testName,
Passed: !t.Failed(),
Histories: histories,
}
kvsJSON := toJSON(o)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/empty_db:_delete_with_no_match_is_nop",
"Passed": true,
"Histories": {
"A": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entries._multiple_valid_time_ranges_active:_set_overlaps_multiple_versions",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entry_-_no_valid_end:_basic_delete",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entry_-_no_valid_end:_error_if_end_valid_time_before_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entry_-_no_valid_end:_error_if_end_valid_time_before_valid_time_(default_valid_time)",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entry_-_no_valid_end:_error_if_end_valid_time_equal_to_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entry_-_no_valid_end:_set_w/_valid_time_end._no_overhang",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestDelete/existing_entry_-_no_valid_end:_set_w/_valid_time_end._original_record_overhands_on_both_sides",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
1 change: 1 addition & 0 deletions memory/_testoutput/TestGet_empty_db_not_found.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/empty_db:_not_found",
"Passed": true,
"Histories": {
"A": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_deletion_with_later_valid_time:_as_of_tx_time_before_update,_as_of_valid_time_before_update",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_deletion_with_later_valid_time:_as_of_tx_time_before_update,_as_of_valid_time_now",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_deletion_with_later_valid_time:_as_of_tx_time_now,_as_of_valid_time_before_update",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_deletion_with_later_valid_time:_not_found_-_default_as_of_times",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_set_with_later_valid_time:_as_of_tx_time_before_update,_as_of_valid_time_before_update",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_set_with_later_valid_time:_as_of_tx_time_before_update,_as_of_valid_time_now",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_set_with_later_valid_time:_as_of_tx_time_now,_as_of_valid_time_before_update",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/initial_set,_and_then_set_with_later_valid_time:_found_-_default_as_of_times",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_found_-_as_of_tx_time_T_in_range",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_found_-_as_of_tx_time_T_in_range_(inclusive)",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_found_-_as_of_valid_time_T_in_range",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_found_-_as_of_valid_time_T_in_range_(inclusive)",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_found_-_default_as_of_times",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_not_found_-_as_of_tx_time_T_before_tx_time_start",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_no_end:_not_found_-_as_of_valid_time_T_before_valid_time_start",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_with_end:_found_-_as_of_valid_and_tx_time_T_in_range",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_with_end:_not_found_-_as_of_valid_time_T_after_valid_time_end",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_with_end:_not_found_-_as_of_valid_time_T_equal_to_valid_time_end_(exclusive)",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestGet/single_set,_with_end:_not_found_-_default_as_of_times",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
1 change: 1 addition & 0 deletions memory/_testoutput/TestHistory_empty_db_not_found.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/empty_db:_not_found",
"Passed": true,
"Histories": {
"A": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/initial_set,_and_then_deletion_with_later_valid_time:_returns_\"deleted\"_versions",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/initial_set,_and_then_set_with_later_valid_time:_return_versions_by_descending_end_transaction_time,_descending_end_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/multiple_versions_have_nil_end_transaction_time:_return_versions_by_descending_end_transaction_time,_descending_end_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/single_set,_no_end:_basic_-_return_1_version",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/single_set,_with_end:_basic_-_return_1_version",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestHistory/version_has_later_transaction_time_start,_but_earlier_transaction_time_end:_return_versions_by_descending_end_transaction_time,_descending_end_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestList/A,_B_values:_found_-_as_of_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestList/A,_B_values:_found_-_default_as_of_times",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestList/A,_B_values:_not_found_-_as_of_transaction_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestList/A_values:_found_-_default_as_of_times",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
1 change: 1 addition & 0 deletions memory/_testoutput/TestList_empty_db_not_found.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestList/empty_db:_not_found",
"Passed": true,
"Histories": {
"A": []
}
Expand Down
1 change: 1 addition & 0 deletions memory/_testoutput/TestRobinhoodExample.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestRobinhoodExample",
"Passed": true,
"Histories": {
"user-1": [
{
Expand Down
1 change: 1 addition & 0 deletions memory/_testoutput/TestSet_empty_db_basic_set.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestSet/empty_db:_basic_set",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestSet/empty_db:_basic_set_with_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestSet/empty_db:_basic_set_with_valid_time_and_end_valid_time",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestSet/empty_db:_can_set_value_of_nil",
"Passed": true,
"Histories": {
"A": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestSet/empty_db:_error_if_end_valid_time_before_valid_time",
"Passed": true,
"Histories": {
"A": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"TestName": "TestSet/empty_db:_error_if_end_valid_time_before_valid_time_(default_valid_time)",
"Passed": true,
"Histories": {
"A": []
}
Expand Down
Loading

0 comments on commit 8bd7ea3

Please sign in to comment.