You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- First run downloads PostgreSQL 18 image (~80MB), subsequent runs use cached image
60
55
61
56
### Code Quality
62
57
@@ -73,39 +68,22 @@ go mod tidy
73
68
cd tests && go mod tidy
74
69
```
75
70
76
-
### Docker Development
77
-
78
-
**Build Docker test image:**
79
-
```bash
80
-
make docker-build
81
-
```
82
-
83
-
**Open shell in test container (for debugging):**
84
-
```bash
85
-
make docker-shell
86
-
```
87
-
88
-
**Run tests interactively:**
89
-
```bash
90
-
make docker-run
91
-
```
92
-
93
71
## Test Organization
94
72
95
73
The test suite is located in `tests/` directory with its own `go.mod` that uses a `replace` directive to reference the parent module.
96
74
97
75
**Test files:**
98
-
-`nullable_test.go` - Unit tests for JSON marshaling/unmarshaling and edge cases
99
-
-`postgres_test.go` - Integration tests with PostgreSQL database (requires Docker)
100
-
-`setup_test.go` - Test fixtures and database connection helpers
101
-
102
-
**Test coverage verification:**
103
-
```bash
104
-
cd tests
105
-
# Count test files
106
-
find . -name "*_test.go"| wc -l
107
-
# Should match the number of test files reported by `go test -v`
108
-
```
76
+
-`marshal_test.go` - Comprehensive tests for JSON marshaling/unmarshaling with complex nested structures
77
+
-`nullable_test.go` - Unit tests for nullable value operations and edge cases
78
+
-`postgres_test.go` - Integration tests with PostgreSQL database using testcontainers
79
+
-`setup_test.go` - TestMain setup with testcontainers, database helpers, and cleanup utilities
80
+
81
+
**Test infrastructure:**
82
+
- Uses testcontainers-go to automatically manage PostgreSQL 18 container
83
+
- TestMain in setup_test.go starts container once for all tests
84
+
- Shared database connection stored in package-level `testDB` variable
85
+
-`cleanupTables()` helper truncates tables between tests for isolation
86
+
- Container automatically terminates after tests complete
109
87
110
88
## Working with MarshalJSON/UnmarshalJSON
111
89
@@ -139,13 +117,13 @@ The library integrates with `database/sql` through two interfaces:
139
117
-**Go version:** 1.24.10
140
118
-**Dependencies:**
141
119
-`github.com/google/uuid` - UUID type support
142
-
- Test dependencies: `pgx/v5`, `sqlx`, `testify`
120
+
- Test dependencies: `pgx/v5`, `sqlx`, `testify`, `testcontainers-go`
143
121
144
122
## Common Gotchas
145
123
146
124
1.**Module structure**: Root module (`github.com/ovya/nullable`) and test module (`github.com/ovya/nullable/tests`) are separate. Always run `go mod tidy` in both directories after dependency changes.
147
125
148
-
2.**Test execution**: Integration tests require Docker. Use `make test` for full suite, or run unit tests directly with `go test`in the `tests/` directory.
126
+
2.**Test execution**: Integration tests require Docker to be running (testcontainers uses it). Run `cd tests && go test -v ./...` or `make test`for the full suite.
149
127
150
128
3.**Type constraints**: The generic constraint limits supported types. Adding new primitive types requires updating the constraint in both `NullableI` interface and `Of[T]` struct definition.
0 commit comments