Skip to content

Commit 3bde443

Browse files
committed
feat: add test infrastructure with Makefile, helpers, and integration test setup
Signed-off-by: jbrinkman <joe.brinkman@improving.com>
1 parent c006826 commit 3bde443

File tree

8 files changed

+302
-2
lines changed

8 files changed

+302
-2
lines changed

‎README.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ valkey-ai-tasks/
4343
- Go 1.24 or later
4444
- Valkey server
4545
- Docker and Docker Compose (for containerized deployment)
46+
- GNU Make (for running Makefile commands)
4647

4748
### Installation
4849

@@ -65,6 +66,46 @@ valkey-ai-tasks/
6566
go run cmd/mcpserver/main.go
6667
```
6768

69+
### Running Tests
70+
71+
The project includes a Makefile in the `go` directory with targets for running tests:
72+
73+
1. Run all tests:
74+
```bash
75+
cd go
76+
make test
77+
```
78+
79+
2. Run integration tests only:
80+
```bash
81+
cd go
82+
make integ-test
83+
```
84+
85+
3. Run tests with a filter:
86+
```bash
87+
cd go
88+
make test filter=TestName
89+
```
90+
91+
4. Run tests with verbose output:
92+
```bash
93+
cd go
94+
make test verbose=1
95+
```
96+
97+
5. Generate test coverage report:
98+
```bash
99+
cd go
100+
make coverage
101+
```
102+
103+
6. View all available Makefile targets:
104+
```bash
105+
cd go
106+
make help
107+
```
108+
68109
#### Docker Deployment
69110

70111
1. Clone the repository:

‎go/Makefile‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Makefile for valkey-ai-tasks project
2+
3+
# Go parameters
4+
GOCMD=go
5+
GOBUILD=$(GOCMD) build
6+
GOTEST=$(GOCMD) test
7+
GOGET=$(GOCMD) get
8+
GOMOD=$(GOCMD) mod
9+
GOFMT=$(GOCMD) fmt
10+
11+
# Project directories
12+
TEST_DIR=./tests
13+
INTEG_TEST_DIR=$(TEST_DIR)/integration
14+
15+
# Test parameters
16+
COVERAGE_DIR=./coverage
17+
COVERAGE_FILE=$(COVERAGE_DIR)/coverage.out
18+
COVERAGE_HTML=$(COVERAGE_DIR)/coverage.html
19+
20+
# Default filter is empty (run all tests)
21+
filter?=.
22+
23+
# Default verbosity is off
24+
verbose?=
25+
26+
# Set verbosity flag if verbose is set
27+
ifdef verbose
28+
VERBOSE_FLAG=-v
29+
else
30+
VERBOSE_FLAG=
31+
endif
32+
33+
.PHONY: all build test integ-test clean fmt tidy coverage
34+
35+
# Default target
36+
all: build test
37+
38+
# Build the application
39+
build:
40+
@echo "Building application..."
41+
@$(GOBUILD) ./...
42+
43+
# Run all tests
44+
test:
45+
@echo "Running all tests..."
46+
@$(GOTEST) $(VERBOSE_FLAG) ./... -run $(filter)
47+
48+
# Run only integration tests
49+
integ-test:
50+
@echo "Running integration tests..."
51+
@$(GOTEST) $(VERBOSE_FLAG) ./tests/integration/... -run $(filter)
52+
53+
# Run tests with coverage
54+
coverage:
55+
@echo "Running tests with coverage..."
56+
@mkdir -p $(COVERAGE_DIR)
57+
@$(GOTEST) -coverprofile=$(COVERAGE_FILE) ./...
58+
@$(GOCMD) tool cover -html=$(COVERAGE_FILE) -o $(COVERAGE_HTML)
59+
@echo "Coverage report generated at $(COVERAGE_HTML)"
60+
61+
# Format code
62+
fmt:
63+
@echo "Formatting code..."
64+
@$(GOFMT) ./...
65+
66+
# Update dependencies
67+
tidy:
68+
@echo "Updating dependencies..."
69+
@$(GOMOD) tidy
70+
71+
# Clean build artifacts
72+
clean:
73+
@echo "Cleaning build artifacts..."
74+
@rm -rf $(COVERAGE_DIR)
75+
@find . -type f -name "*.test" -delete
76+
77+
# Help target
78+
help:
79+
@echo "Available targets:"
80+
@echo " all : Build and run tests"
81+
@echo " build : Build the application"
82+
@echo " test : Run all tests"
83+
@echo " Usage: make test [filter=TestName] [verbose=1]"
84+
@echo " integ-test : Run integration tests only"
85+
@echo " Usage: make integ-test [filter=TestName] [verbose=1]"
86+
@echo " coverage : Generate test coverage report"
87+
@echo " fmt : Format code"
88+
@echo " tidy : Update dependencies"
89+
@echo " clean : Clean build artifacts"
90+
@echo " help : Show this help message"

‎go/go.mod‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ toolchain go1.24.2
77
require (
88
github.com/google/uuid v1.6.0
99
github.com/mark3labs/mcp-go v0.32.0
10+
github.com/stretchr/testify v1.10.0
1011
github.com/valkey-io/valkey-glide/go/v2 v2.0.0-rc6
1112
)
1213

1314
require (
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/pmezard/go-difflib v1.0.0 // indirect
1417
github.com/spf13/cast v1.7.1 // indirect
1518
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
1619
google.golang.org/protobuf v1.33.0 // indirect
20+
gopkg.in/yaml.v3 v3.0.1 // indirect
1721
)

‎go/go.sum‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
1818
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
1919
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
2020
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
21-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
22-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
21+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
22+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2323
github.com/valkey-io/valkey-glide/go/v2 v2.0.0-rc6 h1:kUUNaXrrEiMD5oLq97Dt+XHwOADpl5qjaQ5yznA4Q8k=
2424
github.com/valkey-io/valkey-glide/go/v2 v2.0.0-rc6/go.mod h1:LK5zmODJa5xnxZndarh1trntExb3GVGJXz4GwDCagho=
2525
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
2626
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
2727
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
2828
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
29+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
30+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
31+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2932
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3033
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

‎go/tests/README.md‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Testing Directory Structure
2+
3+
This directory contains the testing infrastructure for the valkey-ai-tasks project.
4+
5+
## Directory Structure
6+
7+
- `integration/`: Contains integration tests that verify the interaction between different components of the system
8+
- `mocks/`: Contains mock implementations of interfaces used in testing
9+
- `utils/`: Contains utility functions and helpers for testing
10+
11+
## Dependencies
12+
13+
This project uses the following testing libraries:
14+
15+
- [Testify](https://github.com/stretchr/testify): A toolkit with common assertions and mocks that is compatible with the standard library
16+
17+
## Running Tests
18+
19+
To run all tests:
20+
21+
```bash
22+
cd /path/to/valkey-ai-tasks/go
23+
go test ./tests/...
24+
```
25+
26+
To run specific test categories:
27+
28+
```bash
29+
# Run integration tests only
30+
go test ./tests/integration/...
31+
32+
# Run a specific test file
33+
go test ./tests/integration/specific_test.go
34+
```
35+
36+
To run tests with verbose output:
37+
38+
```bash
39+
go test -v ./tests/...
40+
```
41+
42+
## Writing Tests
43+
44+
When adding new tests:
45+
46+
1. Place integration tests in the appropriate subdirectory under `integration/`
47+
2. Add mock implementations to the `mocks/` directory
48+
3. Use Testify's assertion and mock packages for testing
49+
4. Use utility functions from `utils/` for common testing operations
50+
5. Follow Go testing best practices and naming conventions
51+
52+
### Example Test
53+
54+
```go
55+
func TestSomething(t *testing.T) {
56+
// Use the test utilities
57+
ctx, req, cancel := utils.SetupTest(t)
58+
defer utils.CleanupTest(t, cancel)
59+
60+
// Your test code here
61+
result := SomeFunction()
62+
63+
// Use testify assertions
64+
req.Equal(expected, result)
65+
req.NoError(err)
66+
}
67+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package integration_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/jbrinkman/valkey-ai-tasks/go/tests/utils"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
// TestExample is a simple example integration test
11+
func TestExample(t *testing.T) {
12+
// Use the test utilities
13+
ctx, req, cancel := utils.SetupTest(t)
14+
defer utils.CleanupTest(t, cancel)
15+
16+
// This is just a placeholder test to verify the integration test structure
17+
assert.NotNil(t, ctx)
18+
req.True(true, "This test should always pass")
19+
}

‎go/tests/utils/test_helpers.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Package utils provides testing utilities for the valkey-ai-tasks project
2+
package utils
3+
4+
import (
5+
"context"
6+
"testing"
7+
"time"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// TestContext returns a context with timeout for use in tests
13+
func TestContext(t *testing.T) (context.Context, context.CancelFunc) {
14+
t.Helper()
15+
return context.WithTimeout(context.Background(), 5*time.Second)
16+
}
17+
18+
// RequireTestify returns a testify require instance for cleaner assertions
19+
// This is just a convenience function to make test code more readable
20+
func RequireTestify(t *testing.T) *require.Assertions {
21+
t.Helper()
22+
return require.New(t)
23+
}
24+
25+
// SetupTest is a helper function to set up common test requirements
26+
// It returns a context with timeout and a testify require instance
27+
func SetupTest(t *testing.T) (context.Context, *require.Assertions, context.CancelFunc) {
28+
t.Helper()
29+
ctx, cancel := TestContext(t)
30+
req := RequireTestify(t)
31+
return ctx, req, cancel
32+
}
33+
34+
// CleanupTest is a helper function to clean up after tests
35+
func CleanupTest(t *testing.T, cancel context.CancelFunc) {
36+
t.Helper()
37+
cancel()
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package utils_test
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/jbrinkman/valkey-ai-tasks/go/tests/utils"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestTestContext(t *testing.T) {
12+
ctx, cancel := utils.TestContext(t)
13+
defer cancel()
14+
15+
// Verify that the context has a deadline
16+
deadline, hasDeadline := ctx.Deadline()
17+
assert.True(t, hasDeadline)
18+
assert.WithinDuration(t, time.Now().Add(5*time.Second), deadline, 100*time.Millisecond)
19+
}
20+
21+
func TestRequireTestify(t *testing.T) {
22+
req := utils.RequireTestify(t)
23+
24+
// Simple test to verify the require instance works
25+
req.True(true, "This should pass")
26+
}
27+
28+
func TestSetupTest(t *testing.T) {
29+
ctx, req, cancel := utils.SetupTest(t)
30+
defer utils.CleanupTest(t, cancel)
31+
32+
// Verify that the context has a deadline
33+
_, hasDeadline := ctx.Deadline()
34+
assert.True(t, hasDeadline)
35+
36+
// Verify that the require instance works
37+
req.NotNil(ctx, "Context should not be nil")
38+
}

0 commit comments

Comments
 (0)