Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .cursor/rules/tests.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
description:
globs:
alwaysApply: false
---
Write tests using TDD with the hydronica.trial package following this pattern.
The most important thing is to keep things as simple and understandable as possible.

```
func TestFunction(t *testing.T) {
// basic function that takes the table's input and returns the output value and an error.
// All errors cases should be handled as an error response
// if no errors return nil in the second value
// Keep the input and output values as simple as possible, preferable primitive types or the exact values of the function being tested
// do not create inline structs, define the struct in the test function first, if a simple struct is needed
fn := func(i string) (RawJSON, error) {
var v RawJSON
err := json.Unmarshal([]byte(i), &v)
return v, err
}
// Tables (test cases) should be clear and as simple as possible to provide logical coverage.
cases := trial.Cases[string, RawJSON]{
"test_case": {
Input:{},
Expected:{},
}
}

trial.New(fn, cases).SubTest(t)
}
```

When dealing time using the following helper functions
- TimeHour(s string) - uses format "2006-01-02T15"
- TimeDay(s string) - uses format "2006-01-02"
- Time(layout string, value)
- Times(layout string, values ...string)
- TimeP(layout string, s string) returns a *time.Time
Loading