Skip to content

Commit f3d3a53

Browse files
committed
feat: Add comprehensive CI/CD pipeline and test suite with dependency upgrades
Signed-off-by: gitsrc <34047788+gitsrc@users.noreply.github.com>
1 parent 6bde573 commit f3d3a53

File tree

15 files changed

+1726
-411
lines changed

15 files changed

+1726
-411
lines changed

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
go-version: [1.25.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: ${{ matrix.go-version }}
25+
26+
- name: Install dependencies
27+
run: make deps
28+
29+
- name: Format check
30+
run: make fmt
31+
32+
- name: Vet code
33+
run: make vet
34+
35+
- name: Run P2P tests
36+
run: cd pkg/p2p && go test -v -race -timeout=60s
37+
38+
- name: Run example tests
39+
run: cd example/kvdb && go test -v -race
40+
41+
- name: Build example
42+
run: make example
43+
44+
build:
45+
name: Build
46+
runs-on: ubuntu-latest
47+
strategy:
48+
matrix:
49+
go-version: [1.25.x]
50+
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
55+
- name: Set up Go
56+
uses: actions/setup-go@v4
57+
with:
58+
go-version: ${{ matrix.go-version }}
59+
60+
- name: Install dependencies
61+
run: make deps
62+
63+
- name: Build
64+
run: make build
65+
66+
- name: Upload build artifacts
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: icefiredb-crdt-kv
70+
path: build/
71+
retention-days: 7
72+
73+
security:
74+
name: Security Scan
75+
runs-on: ubuntu-latest
76+
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
81+
- name: Set up Go
82+
uses: actions/setup-go@v4
83+
with:
84+
go-version: '1.25'
85+
86+
- name: Run GoSec
87+
uses: securego/gosec@master
88+
with:
89+
args: '-exclude=G204 ./...'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ globaldb-example
2222
crdtkvdb
2323

2424
example/example
25+
build

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Makefile for IceFireDB CRDT-KV
2+
3+
# Variables
4+
BINARY_NAME := icefiredb-crdt-kv
5+
EXAMPLE_BINARY := kvdb-example
6+
BUILD_DIR := ./build
7+
EXAMPLE_DIR := ./example/kvdb
8+
9+
# Go parameters
10+
GOCMD := go
11+
GOBUILD := $(GOCMD) build
12+
GOCLEAN := $(GOCMD) clean
13+
GOTEST := $(GOCMD) test
14+
GOGET := $(GOCMD) get
15+
GOMOD := $(GOCMD) mod
16+
17+
# Default target
18+
all: build test
19+
20+
# Build the main library
21+
build:
22+
@echo "Building library..."
23+
mkdir -p $(BUILD_DIR)
24+
$(GOBUILD) ./...
25+
26+
# Build the example application
27+
example:
28+
@echo "Building example application..."
29+
mkdir -p $(BUILD_DIR)
30+
cd $(EXAMPLE_DIR) && $(GOBUILD) -o ../../$(BUILD_DIR)/$(EXAMPLE_BINARY)
31+
32+
# Run all tests
33+
test:
34+
@echo "Running all tests..."
35+
$(GOTEST) -v -race ./...
36+
37+
# Run unit tests only (skip integration tests)
38+
test-unit:
39+
@echo "Running unit tests..."
40+
$(GOTEST) -v -race -run "TestCRDTKeyValueDB_Mock|TestCRDTKeyValueDB_Fast|TestPrintVal|TestMainFunctionExists|TestPubSubHandleType|TestGenerateCID|TestNewP2P|TestP2P_Close|TestP2P_MultipleInstances|TestP2P_NetworkOperations|TestPubSubHandleType_String|TestP2P_ContextCancellation" ./...
41+
42+
# Run integration tests only
43+
test-integration:
44+
@echo "Running integration tests..."
45+
$(GOTEST) -v -race -run "Integration|MultiNode|Concurrent" ./...
46+
47+
# Run tests with coverage
48+
test-coverage:
49+
@echo "Running tests with coverage..."
50+
$(GOTEST) -v -race -coverprofile=coverage.out ./...
51+
$(GOCMD) tool cover -html=coverage.out -o coverage.html
52+
@echo "Coverage report generated: coverage.html"
53+
54+
# Run tests with coverage and show summary
55+
test-coverage-summary:
56+
@echo "Running tests with coverage summary..."
57+
$(GOTEST) -v -race -coverprofile=coverage.out ./...
58+
$(GOCMD) tool cover -func=coverage.out
59+
60+
# Clean build artifacts
61+
clean:
62+
@echo "Cleaning..."
63+
$(GOCLEAN)
64+
rm -rf $(BUILD_DIR)
65+
66+
# Install dependencies
67+
deps:
68+
@echo "Installing dependencies..."
69+
$(GOMOD) tidy
70+
71+
# Format code
72+
fmt:
73+
@echo "Formatting code..."
74+
$(GOCMD) fmt ./...
75+
76+
# Vet code
77+
vet:
78+
@echo "Vetting code..."
79+
$(GOCMD) vet ./...
80+
81+
# Lint and check code quality
82+
lint: fmt vet
83+
84+
# Run the example application
85+
run-example: example
86+
@echo "Running example application..."
87+
./$(BUILD_DIR)/$(EXAMPLE_BINARY)
88+
89+
# Build and run the example
90+
build-run: example run-example
91+
92+
# Show help
93+
help:
94+
@echo "Available targets:"
95+
@echo " all - Build and test everything"
96+
@echo " build - Build the main library"
97+
@echo " example - Build the example application"
98+
@echo " test - Run all tests with race detection"
99+
@echo " test-unit - Run unit tests only (skip integration)"
100+
@echo " test-integration - Run integration tests only"
101+
@echo " test-coverage - Run tests with HTML coverage report"
102+
@echo " test-coverage-summary - Run tests with coverage summary"
103+
@echo " clean - Clean build artifacts"
104+
@echo " deps - Install dependencies"
105+
@echo " fmt - Format code"
106+
@echo " vet - Vet code"
107+
@echo " lint - Lint and check code quality"
108+
@echo " run-example - Run the example application"
109+
@echo " build-run - Build and run the example"
110+
@echo " help - Show this help message"
111+
112+
.PHONY: all build example test test-coverage test-coverage-summary clean deps fmt vet lint run-example build-run help

example/kvdb/kvdb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func main() {
8585
continue
8686
}
8787
for val := range result.Next() {
88-
fmt.Printf(fmt.Sprintf("%s => %v\n", val.Key, string(val.Value)))
88+
fmt.Printf("%s => %v\n", val.Key, string(val.Value))
8989
}
9090
fmt.Print("> ")
9191
case "query":
@@ -106,7 +106,7 @@ func main() {
106106
continue
107107
}
108108
for val := range result.Next() {
109-
fmt.Printf(fmt.Sprintf("%s => %v\n", val.Key, string(val.Value)))
109+
fmt.Printf("%s => %v\n", val.Key, string(val.Value))
110110
}
111111
fmt.Print("> ")
112112
case "connect":
@@ -127,7 +127,7 @@ func main() {
127127
continue
128128
}
129129
for val := range result.Next() {
130-
fmt.Printf(fmt.Sprintf("%s => %v\n", val.Key, string(val.Value)))
130+
fmt.Printf("%s => %v\n", val.Key, string(val.Value))
131131
}
132132
fmt.Print("> ")
133133
case "bquery":

example/kvdb/kvdb_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestPrintVal(t *testing.T) {
10+
// This is a simple test for the printVal function
11+
// Since it just prints to stdout, we mainly test that it doesn't panic
12+
13+
tests := []struct {
14+
name string
15+
input interface{}
16+
}{
17+
{
18+
name: "string value",
19+
input: "test string",
20+
},
21+
{
22+
name: "integer value",
23+
input: 123,
24+
},
25+
{
26+
name: "nil value",
27+
input: nil,
28+
},
29+
{
30+
name: "error value",
31+
input: assert.AnError,
32+
},
33+
}
34+
35+
for _, tt := range tests {
36+
t.Run(tt.name, func(t *testing.T) {
37+
// This should not panic
38+
printVal(tt.input)
39+
})
40+
}
41+
}
42+
43+
func TestMainFunctionExists(t *testing.T) {
44+
// This test simply verifies that the main function exists
45+
// and the package compiles correctly
46+
assert.NotNil(t, main)
47+
}

0 commit comments

Comments
 (0)