Skip to content

Commit

Permalink
Add test descriptions (#30)
Browse files Browse the repository at this point in the history
* add descriptions to TestOutput
* add better description for TestRobinhoodExample
* bump golangci-lint version. remove golint
  • Loading branch information
elh authored Jul 17, 2023
1 parent 9a7df5b commit 8ae43de
Show file tree
Hide file tree
Showing 94 changed files with 255 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.33.0 # elh: my current version
version: v1.53.3 # elh: my current version
args: --timeout 5m
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ test-check-output:
git diff --exit-code

# lint
# run golint because I like the exported comment warnings. It does not fail the run.
lint:
golint ./...
golangci-lint run

######################################################### wasm #########################################################
Expand Down
26 changes: 14 additions & 12 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(t, 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(t, 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(t, 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 @@ -1261,7 +1261,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(t, 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 @@ -1617,7 +1617,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(t, 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 @@ -1652,14 +1652,15 @@ 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
TestName string
Passed bool // true is test passed
Histories map[string][]*VersionedKV // key -> history
Description string // optional description. Markdown is supported.
}

// 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(t *testing.T, db DB, keys []string, testName string) {
func WriteOutputHistory(t *testing.T, db DB, keys []string, testName, description string) {
if !outputHistory {
return
}
Expand All @@ -1676,9 +1677,10 @@ func WriteOutputHistory(t *testing.T, db DB, keys []string, testName string) {
histories[key] = kvs
}
o := TestOutput{
TestName: testName,
Passed: !t.Failed(),
Histories: histories,
TestName: testName,
Passed: !t.Failed(),
Histories: histories,
Description: description,
}
kvsJSON := toJSON(o)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"Passed": true,
"Histories": {
"A": []
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
3 changes: 2 additions & 1 deletion memory/_testoutput/TestGet_empty_db_not_found.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"Passed": true,
"Histories": {
"A": []
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": "2022-01-03T00:00:00Z"
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": "2022-01-03T00:00:00Z"
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": "2022-01-03T00:00:00Z"
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": "2022-01-03T00:00:00Z"
}
]
}
},
"Description": ""
}
3 changes: 2 additions & 1 deletion memory/_testoutput/TestHistory_empty_db_not_found.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"Passed": true,
"Histories": {
"A": []
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"ValidTimeEnd": "2022-01-02T00:00:00Z"
}
]
}
},
"Description": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"ValidTimeEnd": null
}
]
}
},
"Description": ""
}
Loading

0 comments on commit 8ae43de

Please sign in to comment.