aboutsummaryrefslogtreecommitdiff
path: root/test/fuse_integration/Makefile
blob: c92fe55ffeafbd739827d4e71c6699ea79c82199 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# SeaweedFS FUSE Integration Testing Makefile

# Configuration
WEED_BINARY := weed
GO_VERSION := 1.21
TEST_TIMEOUT := 30m
COVERAGE_FILE := coverage.out

# Default target
.DEFAULT_GOAL := help

# Check if weed binary exists
check-binary:
	@if [ ! -f "$(WEED_BINARY)" ]; then \
		echo "❌ SeaweedFS binary not found at $(WEED_BINARY)"; \
		echo "   Please run 'make' in the root directory first"; \
		exit 1; \
	fi
	@echo "✅ SeaweedFS binary found"

# Check FUSE installation
check-fuse:
	@if command -v fusermount >/dev/null 2>&1; then \
		echo "✅ FUSE is installed (Linux)"; \
	elif command -v umount >/dev/null 2>&1 && [ "$$(uname)" = "Darwin" ]; then \
		echo "✅ FUSE is available (macOS)"; \
	else \
		echo "❌ FUSE not found. Please install:"; \
		echo "   Ubuntu/Debian: sudo apt-get install fuse"; \
		echo "   CentOS/RHEL:   sudo yum install fuse"; \
		echo "   macOS:         brew install macfuse"; \
		exit 1; \
	fi

# Check Go version
check-go:
	@go version | grep -q "go1\.[2-9][0-9]" || \
	go version | grep -q "go1\.2[1-9]" || \
	(echo "❌ Go $(GO_VERSION)+ required. Current: $$(go version)" && exit 1)
	@echo "✅ Go version check passed"

# Verify all prerequisites
check-prereqs: check-go check-fuse
	@echo "✅ All prerequisites satisfied"

# Build the SeaweedFS binary (if needed)
build:
	@echo "🔨 Building SeaweedFS..."
	cd ../.. && make
	@echo "✅ Build complete"

# Initialize go module (if needed)
init-module:
	@if [ ! -f go.mod ]; then \
		echo "📦 Initializing Go module..."; \
		go mod init seaweedfs-fuse-tests; \
		go mod tidy; \
	fi

# Run all tests
test: check-prereqs init-module
	@echo "🧪 Running all FUSE integration tests..."
	go test -v -timeout $(TEST_TIMEOUT) ./...

# Run tests with coverage
test-coverage: check-prereqs init-module
	@echo "🧪 Running tests with coverage..."
	go test -v -timeout $(TEST_TIMEOUT) -coverprofile=$(COVERAGE_FILE) ./...
	go tool cover -html=$(COVERAGE_FILE) -o coverage.html
	@echo "📊 Coverage report generated: coverage.html"

# Run specific test categories
test-basic: check-prereqs init-module
	@echo "🧪 Running basic file operations tests..."
	go test -v -timeout $(TEST_TIMEOUT) -run TestBasicFileOperations

test-directory: check-prereqs init-module
	@echo "🧪 Running directory operations tests..."
	go test -v -timeout $(TEST_TIMEOUT) -run TestDirectoryOperations

test-concurrent: check-prereqs init-module
	@echo "🧪 Running concurrent operations tests..."
	go test -v -timeout $(TEST_TIMEOUT) -run TestConcurrentFileOperations

test-stress: check-prereqs init-module
	@echo "🧪 Running stress tests..."
	go test -v -timeout $(TEST_TIMEOUT) -run TestStressOperations

test-large-files: check-prereqs init-module
	@echo "🧪 Running large file tests..."
	go test -v -timeout $(TEST_TIMEOUT) -run TestLargeFileOperations

# Run tests with debugging enabled
test-debug: check-prereqs init-module
	@echo "🔍 Running tests with debug output..."
	go test -v -timeout $(TEST_TIMEOUT) -args -debug

# Run tests and keep temp files for inspection
test-no-cleanup: check-prereqs init-module
	@echo "🧪 Running tests without cleanup (for debugging)..."
	go test -v -timeout $(TEST_TIMEOUT) -args -no-cleanup

# Quick smoke test
test-smoke: check-prereqs init-module
	@echo "💨 Running smoke tests..."
	go test -v -timeout 5m -run TestBasicFileOperations/CreateAndReadFile

# Run benchmarks
benchmark: check-prereqs init-module
	@echo "📈 Running benchmarks..."
	go test -v -timeout $(TEST_TIMEOUT) -bench=. -benchmem

# Validate test files compile
validate: init-module
	@echo "✅ Validating test files..."
	go build -o /dev/null ./...
	@echo "✅ All test files compile successfully"

# Clean up generated files
clean:
	@echo "🧹 Cleaning up..."
	rm -f $(COVERAGE_FILE) coverage.html
	rm -rf /tmp/seaweedfs_fuse_test_*
	go clean -testcache
	@echo "✅ Cleanup complete"

# Format Go code
fmt:
	@echo "🎨 Formatting Go code..."
	go fmt ./...

# Run linter
lint:
	@echo "🔍 Running linter..."
	@if command -v golangci-lint >/dev/null 2>&1; then \
		golangci-lint run; \
	else \
		echo "⚠️  golangci-lint not found, running go vet instead"; \
		go vet ./...; \
	fi

# Run all quality checks
check: validate lint fmt
	@echo "✅ All quality checks passed"

# Install development dependencies
install-deps:
	@echo "📦 Installing development dependencies..."
	go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
	go mod download
	go mod tidy

# Quick development setup
setup: install-deps build check-prereqs
	@echo "🚀 Development environment ready!"

# Docker-based testing
test-docker:
	@echo "🐳 Running tests in Docker..."
	docker build -t seaweedfs-fuse-tests -f Dockerfile.test ../..
	docker run --rm --privileged seaweedfs-fuse-tests

# Create Docker test image
docker-build:
	@echo "🐳 Building Docker test image..."
	@cat > Dockerfile.test << 'EOF' ;\
FROM golang:$(GO_VERSION) ;\
RUN apt-get update && apt-get install -y fuse ;\
WORKDIR /seaweedfs ;\
COPY . . ;\
RUN make ;\
WORKDIR /seaweedfs/test/fuse ;\
RUN go mod init seaweedfs-fuse-tests && go mod tidy ;\
CMD ["make", "test"] ;\
EOF

# GitHub Actions workflow
generate-workflow:
	@echo "📝 Generating GitHub Actions workflow..."
	@mkdir -p ../../.github/workflows
	@cat > ../../.github/workflows/fuse-integration.yml << 'EOF' ;\
name: FUSE Integration Tests ;\
 ;\
on: ;\
  push: ;\
    branches: [ master, main ] ;\
  pull_request: ;\
    branches: [ master, main ] ;\
 ;\
jobs: ;\
  fuse-integration: ;\
    runs-on: ubuntu-latest ;\
    timeout-minutes: 45 ;\
     ;\
    steps: ;\
    - name: Checkout code ;\
      uses: actions/checkout@v4 ;\
       ;\
    - name: Set up Go ;\
      uses: actions/setup-go@v4 ;\
      with: ;\
        go-version: '$(GO_VERSION)' ;\
         ;\
    - name: Install FUSE ;\
      run: sudo apt-get update && sudo apt-get install -y fuse ;\
       ;\
    - name: Build SeaweedFS ;\
      run: make ;\
       ;\
    - name: Run FUSE Integration Tests ;\
      run: | ;\
        cd test/fuse ;\
        make test ;\
         ;\
    - name: Upload test artifacts ;\
      if: failure() ;\
      uses: actions/upload-artifact@v3 ;\
      with: ;\
        name: test-logs ;\
        path: /tmp/seaweedfs_fuse_test_* ;\
EOF
	@echo "✅ GitHub Actions workflow generated"

# Performance profiling
profile: check-prereqs init-module
	@echo "📊 Running performance profiling..."
	go test -v -timeout $(TEST_TIMEOUT) -cpuprofile cpu.prof -memprofile mem.prof -bench=.
	@echo "📊 Profiles generated: cpu.prof, mem.prof"
	@echo "📊 View with: go tool pprof cpu.prof"

# Memory leak detection
test-memory: check-prereqs init-module
	@echo "🔍 Running memory leak detection..."
	go test -v -timeout $(TEST_TIMEOUT) -race -test.memprofile mem.prof

# List available test functions
list-tests:
	@echo "📋 Available test functions:"
	@grep -r "^func Test" *.go | sed 's/.*func \(Test[^(]*\).*/  \1/' | sort

# Get test status and statistics
test-stats: check-prereqs init-module
	@echo "📊 Test statistics:"
	@go test -v ./... | grep -E "(PASS|FAIL|RUN)" | \
		awk '{ \
			if ($$1 == "RUN") tests++; \
			else if ($$1 == "PASS") passed++; \
			else if ($$1 == "FAIL") failed++; \
		} END { \
			printf "  Total tests: %d\n", tests; \
			printf "  Passed: %d\n", passed; \
			printf "  Failed: %d\n", failed; \
			printf "  Success rate: %.1f%%\n", (passed/tests)*100; \
		}'

# Watch for file changes and run tests
watch:
	@echo "👀 Watching for changes..."
	@if command -v entr >/dev/null 2>&1; then \
		find . -name "*.go" | entr -c make test-smoke; \
	else \
		echo "⚠️  'entr' not found. Install with: apt-get install entr"; \
		echo "   Falling back to manual test run"; \
		make test-smoke; \
	fi

# Show help
help:
	@echo "SeaweedFS FUSE Integration Testing"
	@echo "=================================="
	@echo ""
	@echo "Prerequisites:"
	@echo "  make check-prereqs    - Check all prerequisites"
	@echo "  make setup           - Complete development setup"
	@echo "  make build           - Build SeaweedFS binary"
	@echo ""
	@echo "Testing:"
	@echo "  make test            - Run all tests"
	@echo "  make test-basic      - Run basic file operations tests"
	@echo "  make test-directory  - Run directory operations tests"
	@echo "  make test-concurrent - Run concurrent operations tests"
	@echo "  make test-stress     - Run stress tests"
	@echo "  make test-smoke      - Quick smoke test"
	@echo "  make test-coverage   - Run tests with coverage report"
	@echo ""
	@echo "Debugging:"
	@echo "  make test-debug      - Run tests with debug output"
	@echo "  make test-no-cleanup - Keep temp files for inspection"
	@echo "  make profile         - Performance profiling"
	@echo "  make test-memory     - Memory leak detection"
	@echo ""
	@echo "Quality:"
	@echo "  make validate        - Validate test files compile"
	@echo "  make lint            - Run linter"
	@echo "  make fmt             - Format code"
	@echo "  make check           - Run all quality checks"
	@echo ""
	@echo "Utilities:"
	@echo "  make clean           - Clean up generated files"
	@echo "  make list-tests      - List available test functions"
	@echo "  make test-stats      - Show test statistics"
	@echo "  make watch           - Watch files and run smoke tests"
	@echo ""
	@echo "Docker & CI:"
	@echo "  make test-docker     - Run tests in Docker"
	@echo "  make generate-workflow - Generate GitHub Actions workflow"

.PHONY: help check-prereqs check-binary check-fuse check-go build init-module \
        test test-coverage test-basic test-directory test-concurrent test-stress \
        test-large-files test-debug test-no-cleanup test-smoke benchmark validate \
        clean fmt lint check install-deps setup test-docker docker-build \
        generate-workflow profile test-memory list-tests test-stats watch