-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (103 loc) · 3.17 KB
/
Makefile
File metadata and controls
122 lines (103 loc) · 3.17 KB
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
.PHONY: build test test-unit test-integration run-server run-client clean install lint fmt help
# Binary name
BINARY_NAME=broadcast-server
MAIN_PATH=./cmd/broadcast-server
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
# Detect CGO support for race flag
CGO_ENABLED := $(shell $(GOCMD) env CGO_ENABLED)
RACE := $(if $(filter 1,$(CGO_ENABLED)),-race,)
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
$(GOBUILD) -o $(BINARY_NAME) $(MAIN_PATH)
@echo "Build complete: ./$(BINARY_NAME)"
# Install dependencies
install:
@echo "Installing dependencies..."
$(GOGET) github.com/gorilla/websocket@latest
$(GOGET) github.com/spf13/cobra@latest
$(GOGET) github.com/stretchr/testify@latest
$(GOMOD) tidy
@echo "Dependencies installed"
# Run all tests
test: test-unit test-integration
# Run unit tests
test-unit:
@echo "Running unit tests..."
$(GOTEST) -v $(RACE) -coverprofile=coverage.out ./pkg/... ./internal/...
@echo "Unit tests complete"
# Run integration tests
test-integration:
@echo "Running integration tests..."
$(GOTEST) -v $(RACE) ./test/integration/...
@echo "Integration tests complete"
# Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v $(RACE) -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Quick test (skip integration)
test-quick:
@echo "Running quick tests..."
$(GOTEST) -short -v ./...
# Run the server
run-server: build
./$(BINARY_NAME) start
# Run the client
run-client: build
./$(BINARY_NAME) connect
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
@echo "Formatting complete"
# Run linter
lint:
@echo "Running linter..."
$(GOVET) ./...
@echo "Linting complete"
# Clean build artifacts
clean:
@echo "Cleaning..."
rm -f $(BINARY_NAME)
rm -f coverage.out coverage.html
$(GOCMD) clean
@echo "Clean complete"
# Run server with custom port
run-server-custom:
./$(BINARY_NAME) start --port 9090
# Install the binary to $GOPATH/bin
install-bin: build
@echo "Installing binary to GOPATH/bin..."
cp $(BINARY_NAME) $(GOPATH)/bin/
@echo "Installation complete"
# Run benchmarks
benchmark:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Display help
help:
@echo "Available targets:"
@echo " build - Build the application"
@echo " install - Install dependencies"
@echo " test - Run all tests"
@echo " test-unit - Run unit tests only"
@echo " test-integration - Run integration tests only"
@echo " test-coverage - Run tests with coverage report"
@echo " test-quick - Run quick tests (skip integration)"
@echo " run-server - Build and run the server"
@echo " run-client - Build and run the client"
@echo " fmt - Format code"
@echo " lint - Run linter"
@echo " clean - Clean build artifacts"
@echo " install-bin - Install binary to GOPATH/bin"
@echo " benchmark - Run benchmarks"
@echo " help - Display this help message"