Skip to content

Commit 355c200

Browse files
committed
test: Implement Phase 1 - Testing and error handling improvements
Add comprehensive test suite: - JSON parsing tests for wrapped/unwrapped formats - Resource calculation and leftover computation tests - Error handling tests for invalid inputs - Test coverage: 9 test cases, all passing Improve error handling: - Add proper error handling for strconv.ParseInt (main.go:141-148) - Provide clear error messages for invalid CPU/Memory values Add CI/CD infrastructure: - Create GitHub Actions workflow for automated testing - Include go test, go vet, go fmt checks - Add build verification step Other improvements: - Update .gitignore to exclude coverage.out - Format code with gofmt 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f24dacd commit 355c200

File tree

4 files changed

+461
-2
lines changed

4 files changed

+461
-2
lines changed

.github/workflows/test.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- claude/**
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: "go.mod"
20+
21+
- name: Run tests
22+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
23+
24+
- name: Display coverage
25+
run: go tool cover -func=coverage.out
26+
27+
- name: Check coverage threshold
28+
run: |
29+
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
30+
echo "Total coverage: ${coverage}%"
31+
if (( $(echo "$coverage < 50" | bc -l) )); then
32+
echo "Warning: Coverage is below 50%"
33+
fi
34+
35+
lint:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
- name: Setup Go
42+
uses: actions/setup-go@v5
43+
with:
44+
go-version-file: "go.mod"
45+
46+
- name: Run go vet
47+
run: go vet ./...
48+
49+
- name: Run go fmt
50+
run: |
51+
if [ -n "$(gofmt -l .)" ]; then
52+
echo "Go code is not formatted:"
53+
gofmt -d .
54+
exit 1
55+
fi
56+
57+
build:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
63+
- name: Setup Go
64+
uses: actions/setup-go@v5
65+
with:
66+
go-version-file: "go.mod"
67+
68+
- name: Build
69+
run: go build -v -o bin/ecsource main.go
70+
71+
- name: Verify binary
72+
run: ./bin/ecsource --version

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
bin/ecsource
2+
coverage.out

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ func main() {
138138
allMemoryReservation += containerDefinition.MemoryReservation
139139
}
140140
table.Append([]string{"sum of all container", fmt.Sprintf("%d", allCPU), fmt.Sprintf("%d", allMemory), fmt.Sprintf("%d", allMemoryReservation)})
141-
taskCPU, _ := strconv.ParseInt(taskDefinition.CPU, 10, 64)
142-
taskMemory, _ := strconv.ParseInt(taskDefinition.Memory, 10, 64)
141+
taskCPU, err := strconv.ParseInt(taskDefinition.CPU, 10, 64)
142+
if err != nil {
143+
log.Fatalf("failed to parse task CPU '%s': %v", taskDefinition.CPU, err)
144+
}
145+
taskMemory, err := strconv.ParseInt(taskDefinition.Memory, 10, 64)
146+
if err != nil {
147+
log.Fatalf("failed to parse task Memory '%s': %v", taskDefinition.Memory, err)
148+
}
143149

144150
leftoverCPU := taskCPU - allCPU
145151
leftoverMemory := taskMemory - allMemory

0 commit comments

Comments
 (0)