Skip to content

Commit 010531d

Browse files
author
jxu3
committed
Refactor: Remove existing tests and server implementation
- Deleted proxy_test.go, server.go, and server_test.go files to clean up the codebase. - Added valid_config.json and models_response.json fixtures for testing. - Introduced integration tests for API endpoints in api_test.go. - Created helper functions in testutils for configuration and server mocking. - Implemented unit tests for authentication, configuration, and logging functionalities.
1 parent 2347f6a commit 010531d

File tree

29 files changed

+1676
-2711
lines changed

29 files changed

+1676
-2711
lines changed

Makefile

Lines changed: 96 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,121 @@
11
BINARY=github-copilot-svcs
2-
VERSION ?= dev
2+
CMD_PATH=./cmd/github-copilot-svcs
3+
VERSION?=dev
34

4-
.PHONY: all build test coverage lint security-scan docker-build docker-run install uninstall clean
5-
6-
all: build
5+
.PHONY: build test test-unit test-integration test-e2e test-all clean run dev
76

7+
# Build the binary
88
build:
9-
go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY) .
9+
go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY) $(CMD_PATH)
1010

11-
# Cross-platform builds
12-
build-linux-amd64:
13-
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY)-linux-amd64 .
11+
# Run the application
12+
run: build
13+
./$(BINARY)
1414

15-
build-linux-arm64:
16-
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY)-linux-arm64 .
15+
# Development server with hot reload (requires air: go install github.com/cosmtrek/air@latest)
16+
dev:
17+
air -c .air.toml
1718

18-
build-darwin-amd64:
19-
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY)-darwin-amd64 .
19+
# Run only unit tests
20+
test-unit:
21+
go test -v -race ./test/unit/...
2022

21-
build-darwin-arm64:
22-
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY)-darwin-arm64 .
23+
# Run only integration tests
24+
test-integration:
25+
go test -v -race ./test/integration/...
2326

24-
build-windows-amd64:
25-
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY)-windows-amd64.exe .
27+
# Run only e2e tests
28+
test-e2e:
29+
go test -v -race ./test/e2e/...
2630

27-
build-windows-arm64:
28-
GOOS=windows GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BINARY)-windows-arm64.exe .
31+
# Run all tests
32+
test-all:
33+
go test -v -race ./test/...
2934

30-
# Testing and quality assurance
31-
test:
32-
go test -v -race ./...
35+
# Default test command (unit tests)
36+
test: test-unit
3337

34-
coverage:
35-
go test -v -race -coverprofile=coverage.out ./...
38+
# Test with coverage
39+
test-coverage:
40+
go test -v -race -coverprofile=coverage.out -coverpkg=./internal/...,./cmd/...,./pkg/... ./test/...
3641
go tool cover -html=coverage.out -o coverage.html
42+
go tool cover -func=coverage.out
3743
@echo "Coverage report generated: coverage.html"
3844

39-
lint:
40-
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
41-
golangci-lint run
42-
43-
security-scan:
44-
@which gosec > /dev/null || (echo "Installing gosec..." && go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest)
45-
gosec ./...
46-
47-
# Docker support
48-
docker-build:
49-
docker build -t github-copilot-svcs:$(VERSION) .
50-
51-
docker-run: docker-build
52-
docker run -p 8081:8081 github-copilot-svcs:$(VERSION)
45+
# Test short (skip integration tests)
46+
test-short:
47+
go test -short -v -race ./test/...
5348

54-
docker-compose-up:
55-
docker-compose up --build
56-
57-
docker-compose-down:
58-
docker-compose down
59-
60-
# Installation
61-
install: build
62-
sudo cp $(BINARY) /usr/local/bin/
49+
# Clean test artifacts and build files
50+
clean:
51+
rm -f $(BINARY) coverage.out coverage.html
52+
go clean -testcache
53+
go mod tidy
6354

64-
uninstall:
65-
sudo rm -f /usr/local/bin/$(BINARY)
55+
# Run tests with verbose output and show which tests are running
56+
test-verbose:
57+
go test -v -race ./test/... -run .
6658

67-
# Development commands
68-
run: build
69-
./$(BINARY) run
59+
# Lint the code (requires golangci-lint)
60+
lint:
61+
golangci-lint run
7062

71-
auth:
72-
./$(BINARY) auth
63+
# Format the code
64+
fmt:
65+
go fmt ./...
7366

74-
models:
75-
./$(BINARY) models
67+
# Vet the code
68+
vet:
69+
go vet ./...
7670

77-
config:
78-
./$(BINARY) config
71+
# Install dependencies
72+
deps:
73+
go mod download
74+
go mod verify
7975

80-
status:
81-
./$(BINARY) status
76+
# Update dependencies
77+
update-deps:
78+
go get -u ./...
79+
go mod tidy
8280

83-
refresh:
84-
./$(BINARY) refresh
81+
# Security check (requires gosec: go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest)
82+
security:
83+
gosec ./...
8584

86-
# Cleanup
87-
clean:
88-
rm -f $(BINARY) $(BINARY)-* coverage.out coverage.html
85+
# Generate mocks (requires mockery: go install github.com/vektra/mockery/v2@latest)
86+
mocks:
87+
mockery --all --output=test/mocks
8988

90-
clean-all: clean
91-
docker rmi github-copilot-svcs:$(VERSION) 2>/dev/null || true
89+
# Docker build
90+
docker-build:
91+
docker build -t $(BINARY):$(VERSION) .
92+
93+
# Docker run
94+
docker-run:
95+
docker run -p 8081:8081 $(BINARY):$(VERSION)
96+
97+
# Help
98+
help:
99+
@echo "Available targets:"
100+
@echo " build Build the binary"
101+
@echo " run Build and run the application"
102+
@echo " dev Run development server with hot reload"
103+
@echo " test Run unit tests (default)"
104+
@echo " test-unit Run only unit tests"
105+
@echo " test-integration Run only integration tests"
106+
@echo " test-e2e Run only e2e tests"
107+
@echo " test-all Run all tests"
108+
@echo " test-coverage Run tests with coverage report"
109+
@echo " test-short Run tests (skip integration tests)"
110+
@echo " test-verbose Run tests with verbose output"
111+
@echo " lint Lint the code"
112+
@echo " fmt Format the code"
113+
@echo " vet Vet the code"
114+
@echo " clean Clean build artifacts and test cache"
115+
@echo " deps Install dependencies"
116+
@echo " update-deps Update dependencies"
117+
@echo " security Run security checks"
118+
@echo " mocks Generate mocks"
119+
@echo " docker-build Build Docker image"
120+
@echo " docker-run Run Docker container"
121+
@echo " help Show this help message"

README.md

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ Available platforms:
3535

3636
### Docker Images
3737

38-
Docker images are available on Docker Hub and GitHub Container Registry:
38+
Docker images are automatically built and published to GitHub Container Registry via GitHub Actions:
3939

4040
```bash
41-
# Docker Hub
42-
docker pull <username>/github-copilot-svcs:latest
43-
44-
# GitHub Container Registry
41+
# Pull the latest image
4542
docker pull ghcr.io/privapps/github-copilot-svcs:latest
43+
44+
# Pull a specific version (example)
45+
docker pull ghcr.io/privapps/github-copilot-svcs:v0.0.2
4646
```
4747

48+
Available architectures:
49+
- `linux/amd64`
50+
- `linux/arm64`
51+
4852
### Automated Releases
4953

5054
Releases are automatically created when code is merged to the `main` branch:
@@ -91,20 +95,14 @@ If you have `make` installed, you can build, run, and test the project easily:
9195
```bash
9296
make build # Build the binary
9397
make run # Start the proxy server
94-
make auth # Authenticate with GitHub Copilot
95-
make models # List available models
96-
make config # Show current configuration
98+
make test # Run unit tests
99+
make test-all # Run all tests
100+
make test-coverage # Generate coverage report
97101
make clean # Remove the binary
98-
make build-linux-amd64 # Build for Linux AMD64
99-
make build-linux-arm64 # Build for Linux ARM64
100-
make build-darwin-amd64 # Build for macOS Intel
101-
make build-darwin-arm64 # Build for macOS Apple Silicon
102-
make build-windows-amd64 # Build for Windows AMD64
103-
make build-windows-arm64 # Build for Windows ARM64
104-
make test # Run tests
105-
make coverage # Generate coverage report
106-
make lint # Run linting
107-
make security-scan # Run security analysis
102+
make lint # Run linting
103+
make fmt # Format code
104+
make vet # Run go vet
105+
make security # Run security analysis
108106
make docker-build # Build Docker image
109107
make docker-run # Run Docker container
110108
```
@@ -127,16 +125,14 @@ cp config.example.json ~/.local/share/github-copilot-svcs/config.json
127125

128126
### 3. First Time Setup & Authentication
129127
```bash
130-
make auth
131-
# or manually:
132128
./github-copilot-svcs auth
133129
```
134130

135131
### 4. Start the Proxy Server
136132
```bash
137133
make run
138134
# or manually:
139-
./github-copilot-svcs run
135+
./github-copilot-svcs start
140136
```
141137

142138
## Docker Deployment
@@ -177,7 +173,7 @@ docker exec -it github-copilot-svcs ./github-copilot-svcs auth
177173

178174
| Command | Description |
179175
|---------|-------------|
180-
| `run` or `start` | Start the proxy server |
176+
| `start` | Start the proxy server (default command) |
181177
| `auth` | Authenticate with GitHub Copilot using device flow |
182178
| `status` | Show detailed authentication and token status |
183179
| `config` | Display current configuration details |
@@ -417,7 +413,7 @@ The proxy automatically maps common model names to GitHub Copilot models:
417413
curl http://localhost:8081/health
418414

419415
# View logs (if running in foreground)
420-
./github-copilot-svcs run
416+
./github-copilot-svcs start
421417
```
422418

423419
### Port Conflicts
@@ -474,14 +470,37 @@ print(response)
474470
### Project Structure
475471
```
476472
github-copilot-svcs/
477-
├── main.go # Main application and CLI
478-
├── auth.go # GitHub Copilot authentication
479-
├── proxy.go # Reverse proxy implementation
480-
├── server.go # Server utilities and graceful shutdown
481-
├── transform.go # Request/response transformation
482-
├── cli.go # CLI command handling
483-
├── go.mod # Go module definition
484-
└── README.md # This documentation
473+
├── cmd/
474+
│ └── github-copilot-svcs/
475+
│ └── main.go # Main application entry point
476+
├── internal/ # Private application code
477+
│ ├── auth/
478+
│ │ └── auth.go # GitHub Copilot authentication
479+
│ ├── cli/
480+
│ │ └── cli.go # CLI command handling
481+
│ ├── config/
482+
│ │ └── config.go # Configuration management
483+
│ ├── logger/
484+
│ │ └── logger.go # Structured logging
485+
│ ├── models/
486+
│ │ └── models.go # Model management and mapping
487+
│ ├── proxy/
488+
│ │ └── proxy.go # Reverse proxy implementation
489+
│ └── server/
490+
│ └── server.go # HTTP server and graceful shutdown
491+
├── pkg/ # Public API packages
492+
│ └── transform/
493+
│ └── transform.go # Request/response transformation
494+
├── test/ # Test files organized by type
495+
│ ├── integration/ # Integration tests
496+
│ ├── unit/ # Unit tests
497+
│ └── testutils/ # Test utilities
498+
├── config.example.json # Example configuration
499+
├── docker-compose.yml # Docker Compose setup
500+
├── Dockerfile # Docker image definition
501+
├── Makefile # Build and development tasks
502+
├── go.mod # Go module definition
503+
└── README.md # This documentation
485504
```
486505

487506
### Building from Source
@@ -491,16 +510,31 @@ cd github-copilot-svcs
491510
make build
492511
# or manually:
493512
go mod tidy
494-
go build -o github-copilot-svcs
513+
go build -o github-copilot-svcs ./cmd/github-copilot-svcs
495514
```
496515

497516
### Running Tests
498517
```bash
499-
make test
518+
make test # Run unit tests
519+
make test-all # Run all tests (unit + integration)
520+
make test-coverage # Run tests with coverage report
500521
# or manually:
501-
go test ./...
522+
go test ./test/...
502523
```
503524

525+
### Test Coverage
526+
The project includes comprehensive test coverage:
527+
- **Unit Tests**: Testing individual components (auth, config, logger)
528+
- **Integration Tests**: Testing API endpoints and server functionality
529+
- **Coverage Reports**: HTML and terminal coverage reports available
530+
531+
Generate coverage reports:
532+
```bash
533+
make test-coverage # Generates coverage.html and shows terminal summary
534+
```
535+
536+
Current test coverage: **~45%** across all packages, with excellent coverage in core components like logging (95%+) and configuration (58%+).
537+
504538
## License
505539

506540
Apache License 2.0 - see LICENSE file for details.

0 commit comments

Comments
 (0)