9
Pengembangan dan Pengujian
Repository ini memakai satu Makefile sebagai pintu masuk pekerjaan lokal: setup, compile, fmt, lint, test, dan laporan coverage. Target all merangkai build lalu test (Makefile:1-2). Halaman ini merangkum perintah tersebut, konfigurasi golangci-lint, pola test yang dipakai, dan aturan kontribusi repository.
Alur kerja lokal
Target build bergantung pada compile, fmt, dan lint (Makefile:15-21). Target test bergantung pada fmt dan build, lalu menjalankan go test dengan prefix ENVIRONMENT=test (Makefile:23-24). Akibatnya, satu perintah make test memformat kode, mengompilasi seluruh paket dengan -race, menjalankan golangci-lint, dan baru menjalankan test.
compile menyiapkan direktori out/ sebelum go build -race ./... (Makefile:11-13). Direktori itu dipakai lagi oleh test-cover-html untuk menaruh out/coverage.html (Makefile:26-31).
graph TD
setup["make setup: golangci-lint v2.8.0 + goveralls v0.0.12"] --> fmt["make fmt: go fmt ./..."]
fmt --> compile["make compile: mkdir -p out/ lalu go build -race ./..."]
compile --> lint["make lint: golangci-lint run ./..."]
lint --> test["make test: ENVIRONMENT=test go test -race -covermode=atomic"]
test --> cov["coverage.out"]
cov --> html["make test-cover-html: coverage-all.out lalu out/coverage.html"]
style setup fill:#f59e0b,color:#000
style fmt fill:#2d7d46,color:#fff
style compile fill:#2d7d46,color:#fff
style lint fill:#2d7d46,color:#fff
style test fill:#2d7d46,color:#fff
style cov fill:#8b5cf6,color:#fff
style html fill:#8b5cf6,color:#fff
%% fig: Rantai target Makefile untuk kerja lokal
%% desc: build merangkai fmt, compile, dan lint; test menambahkan go test -race dan menghasilkan coverage.out yang dirakit menjadi laporan HTML.| Target | Prasyarat | Perintah utama | Artefak | Rujukan |
|---|---|---|---|---|
setup | — | mkdir -p $(GOPATH)/bin, lalu go install untuk golangci-lint v2.8.0 dan goveralls v0.0.12 | binary di $(GOPATH)/bin | Makefile:6-9 |
compile | — | mkdir -p out/ lalu go build -race ./... | direktori out/ | Makefile:11-13 |
fmt | — | go fmt ./... | — | Makefile:15-21 |
lint | — | golangci-lint run ./... | — | Makefile:15-21 |
build | compile fmt lint | — | — | Makefile:15-21 |
test | fmt build | ENVIRONMENT=test go test -race -covermode=atomic -coverprofile=coverage.out ./... | coverage.out | Makefile:23-24 |
test-cover-html | — | loop $(ALL_PACKAGES): go test -race -coverprofile=coverage.out -covermode=count per paket, lalu go tool cover -html=coverage-all.out -o out/coverage.html | coverage-all.out, out/coverage.html | Makefile:26-31 |
all | build test | — | — | Makefile:1-2 |
test-cover-html mengambil daftar paket dari ALL_PACKAGES, yaitu keluaran go list ./... yang disaring tanpa vendor (Makefile:4-4).
⚠️
make setupmemakai variabel make$(GOPATH). Bila variabel lingkunganGOPATHtidak diset, perintah pertama mengembang menjadimkdir -p /bin, sehingga binarygolangci-linttidak mendarat di direktori yang ikutPATH(Makefile:6-9).
⚠️
make test-cover-htmlmenulis ulangcoverage.outuntuk setiap paket dan menyambung barisnya kecoverage-all.out. Setelah target itu berjalan,coverage.outhanya berisi hasil paket terakhir, jadi jalankanmake testlagi bila butuhcoverage.oututuh (Makefile:26-31).
Konfigurasi golangci-lint
Berkas .golangci.yml memakai version: "2" dan menyalakan run.tests: true, sehingga berkas _test.go ikut diperiksa. linters.default diset none, lalu linter diaktifkan satu per satu: govet, ineffassign, staticcheck, unused, modernize, dan paralleltest (.golangci.yml:1-121).
| Bagian | Nilai | Rujukan |
|---|---|---|
linters.enable | govet, ineffassign, staticcheck, unused, modernize, paralleltest | .golangci.yml:1-121 |
linters.exclusions | generated: lax; paths: vendor, third_party$, builtin$, examples/ | .golangci.yml:13-192 |
issues | max-issues-per-linter 0, max-same-issues 0 | .golangci.yml:20-323 |
formatters | enable: gofmt, dengan paths eksklusi yang sama | .golangci.yml:20-323 |
Nilai 0 pada max-issues-per-linter dan max-same-issues berarti golangci-lint tidak memotong jumlah temuan yang dilaporkan (.golangci.yml:20-323). Linter paralleltest menjelaskan kebiasaan di repository ini: setiap fungsi Test* memanggil t.Parallel() di baris pertama, seperti pada TestRetrierWithExponentialBackoff (retry_test.go:10-174).
Pola pengujian
Test memakai testify dalam tiga bentuk, yaitu assert, require, dan mock (httpclient/client_test.go:17-195). Paket httpclient mencontohkan pola yang diulang di banyak test: NewClient dengan option, dummyHandler yang memeriksa method dan header, lalu httptest.NewServer sebagai target request (httpclient/client_test.go:22-366). Dependensi github.com/gojek/hystrix-go/hystrix v1.0.0 dan testify v1.11.1 tercatat di go.mod bersama direktif go 1.25 (go.mod:1-87).
Prefix ENVIRONMENT=test muncul di target test (Makefile:23-24) dan diulang pada loop test-cover-html (Makefile:26-31). Karena test dijalankan dengan -race, seluruh paket ikut dibangun dengan -race pula lewat compile (Makefile:11-13).
Siklus request dan retry yang diuji di paket httpclient dibahas di Siklus Request dan Retry, sedangkan perilaku backoff yang diuji TestRetrierWithExponentialBackoff dibahas di Retry dan Backoff.
Aturan kontribusi
CONTRIBUTING.md meminta kontributor membuka issue lebih dulu, mengikuti Effective Go Community Guidelines, dan menyatukan seluruh commit menjadi satu sebelum push dengan pesan yang merujuk bug (CONTRIBUTING.md:6-178). Laporan issue harus jelas, ringkas, memakai judul deskriptif, dan menyertakan potongan kode yang relevan (CONTRIBUTING.md:19-249). pull request memakai topic branch, mengikuti konvensi kode yang sudah ada, dan hanya membahas satu subjek (CONTRIBUTING.md:26-3210).
Riwayat rilis
CHANGELOG.md hanya memuat satu entri, v0.0.1 (2018-JAN-19), berisi initial fork commit dan open-source stepping stones (CHANGELOG.md:3-611). Versi modul saat ini terbaca dari path modul github.com/gojek/heimdall/v8 (go.mod:1-87).
Alur CI
CI berjalan untuk push dan pull_request ke master (.github/workflows/ci.yml:3-712), dengan matriks tiga versi Go: 1.25.x, 1.26.x, dan stable (.github/workflows/ci.yml:13-1513). Sebelum build, cache ~/.cache/go-build dan ~/go/pkg/mod dipulihkan dengan key dari hashFiles('**/go.sum') (.github/workflows/ci.yml:26-3414).
graph LR
trigger["push / pull_request ke master"] --> matrix["matrix go-version: 1.25.x, 1.26.x, stable"]
matrix --> cache["actions/cache: ~/.cache/go-build + ~/go/pkg/mod"]
cache --> setup["make setup"]
setup --> test["make test"]
test --> coveralls["coverallsapp/github-action@v2: coverage.out"]
style trigger fill:#f59e0b,color:#000
style matrix fill:#f59e0b,color:#000
style cache fill:#8b5cf6,color:#fff
style setup fill:#f59e0b,color:#000
style test fill:#2d7d46,color:#fff
style coveralls fill:#2d7d46,color:#fff
%% fig: Jalur job CI
%% desc: Trigger push atau pull request menjalankan job test pada tiga versi Go, memulihkan cache modul, lalu mengunggah coverage.out ke Coveralls.| Langkah | Isi | Rujukan |
|---|---|---|
| Trigger | push dan pull_request ke master | .github/workflows/ci.yml:3-712 |
| Matriks | go-version: ['1.25.x', '1.26.x', 'stable'] | .github/workflows/ci.yml:13-1513 |
| Cache | ~/.cache/go-build, ~/go/pkg/mod, key dari hashFiles('**/go.sum') | .github/workflows/ci.yml:26-3414 |
| Build dan test | make setup lalu make test | .github/workflows/ci.yml:36-4015 |
| Coverage | coverallsapp/github-action@v2, file: coverage.out, format: golang | .github/workflows/ci.yml:42-4716 |
Pipeline memanggil target Makefile yang sama seperti di lokal, yaitu make setup lalu make test (.github/workflows/ci.yml:36-4015). goveralls dipasang oleh setup tetapi tidak dipakai target mana pun; unggahan coverage dikerjakan coverallsapp/github-action@v2 dengan file: coverage.out (.github/workflows/ci.yml:42-4716).