Use neutral names in comments, examples and fixtures
This commit is contained in:
@@ -24,7 +24,7 @@ build:
|
||||
go build ./...
|
||||
|
||||
# Unit tests. The container-backed integration tests skip themselves under
|
||||
# -short, which is how CI runs them: the Kubernetes runners have no Docker.
|
||||
# -short, which is how CI runs them: the runners have no Docker.
|
||||
test:
|
||||
go test -race -count=1 -short ./...
|
||||
|
||||
@@ -61,7 +61,7 @@ clean:
|
||||
rm -f cover.out cover.filtered.out
|
||||
|
||||
# Bump helpers — read the latest semver tag and create the next one. Consumers
|
||||
# pin the resulting v* tag with `go get git.unkin.net/unkin/golib@vX.Y.Z`.
|
||||
# pin the resulting v* tag with `go get github.com/IUCLabs/golib@vX.Y.Z`.
|
||||
_LATEST := $(shell git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1)
|
||||
_BASE := $(if $(_LATEST),$(_LATEST),v0.0.0)
|
||||
_MAJ := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f1)
|
||||
|
||||
@@ -41,8 +41,8 @@ var (
|
||||
// DSNFromEnv builds a libpq/pgx connection string from the environment.
|
||||
//
|
||||
// prefix is prepended to every custom variable name, so a service can namespace
|
||||
// its settings ("ENCAPI_" reads ENCAPI_DBHOST); an empty prefix reads the bare
|
||||
// names the estate's services already use (DBHOST, DBPORT, ...).
|
||||
// its settings ("MYAPP_" reads MYAPP_DBHOST); an empty prefix reads the bare
|
||||
// names (DBHOST, DBPORT, ...).
|
||||
//
|
||||
// Precedence, highest first:
|
||||
//
|
||||
@@ -161,7 +161,7 @@ func connPartsFromEnv(prefix string) (connParts, error) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// DSN renders the estate's standard connection string. User and password are
|
||||
// DSN renders the standard connection string. User and password are
|
||||
// percent-escaped, so a password containing "@" or "/" does not truncate the
|
||||
// host; for values without reserved characters the result is byte-identical to
|
||||
// the fmt.Sprintf builders this replaces.
|
||||
|
||||
+3
-3
@@ -49,11 +49,11 @@ func TestDSNFromEnv(t *testing.T) {
|
||||
name: "bare custom vars with an empty prefix",
|
||||
prefix: "",
|
||||
env: map[string]string{
|
||||
"DBHOST": "pg", "DBPORT": "5432", "DBUSER": "encapi",
|
||||
"DBPASS": "encapi", "DBNAME": "encapi", "DBSSL": "disable",
|
||||
"DBHOST": "pg", "DBPORT": "5432", "DBUSER": "myapp",
|
||||
"DBPASS": "myapp", "DBNAME": "myapp", "DBSSL": "disable",
|
||||
},
|
||||
// Byte-identical to the fmt.Sprintf builder this replaces.
|
||||
want: "postgres://encapi:encapi@pg:5432/encapi?sslmode=disable",
|
||||
want: "postgres://myapp:myapp@pg:5432/myapp?sslmode=disable",
|
||||
},
|
||||
{
|
||||
name: "libpq vars fill in",
|
||||
|
||||
+9
-9
@@ -132,18 +132,18 @@ func (f *fakeDB) discardCount() int {
|
||||
return f.discards
|
||||
}
|
||||
|
||||
// arrproxy pinned its advisory lock key as a literal derived from
|
||||
// FNV-1a/64("arrproxy-migrations"). LockKey must reproduce it exactly, or
|
||||
// adopting this package would silently stop excluding the old deployment.
|
||||
func TestLockKey_MatchesTheEstatesPinnedKey(t *testing.T) {
|
||||
const arrproxyKey int64 = 7816645656172167846
|
||||
if got := LockKey("arrproxy-migrations"); got != arrproxyKey {
|
||||
t.Fatalf("LockKey(%q) = %d, want %d", "arrproxy-migrations", got, arrproxyKey)
|
||||
// A service that hardcoded its advisory lock key as FNV-1a/64 of its lock name
|
||||
// must keep getting the same key from LockKey, or adopting this package would
|
||||
// silently stop excluding the old deployment.
|
||||
func TestLockKey_MatchesPinnedKey(t *testing.T) {
|
||||
const pinnedKey int64 = -8597821083387989636
|
||||
if got := LockKey("myapp-migrations"); got != pinnedKey {
|
||||
t.Fatalf("LockKey(%q) = %d, want %d", "myapp-migrations", got, pinnedKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockKey_IsFNV1a64(t *testing.T) {
|
||||
for _, name := range []string{"", "encapi-migrations", "a much longer lock name"} {
|
||||
for _, name := range []string{"", "myapp-migrations", "a much longer lock name"} {
|
||||
h := fnv.New64a()
|
||||
if _, err := h.Write([]byte(name)); err != nil {
|
||||
t.Fatalf("hash: %v", err)
|
||||
@@ -157,7 +157,7 @@ func TestLockKey_IsFNV1a64(t *testing.T) {
|
||||
// Distinct names must not collide, or two services sharing a cluster would
|
||||
// serialise against each other by accident.
|
||||
func TestLockKey_DistinctNamesDistinctKeys(t *testing.T) {
|
||||
if LockKey("encapi-migrations") == LockKey("artifactapi-migrations") {
|
||||
if LockKey("myapp-migrations") == LockKey("otherapp-migrations") {
|
||||
t.Fatal("two different lock names produced the same key")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package pg holds the estate's shared Postgres plumbing: environment-driven
|
||||
// Package pg holds shared Postgres plumbing: environment-driven
|
||||
// DSN construction, pgxpool construction, read/write splitting across a primary
|
||||
// and a read replica, and the migration runner every service uses to bring its
|
||||
// own schema up to date at startup.
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
// tests. Import it only from _test.go files so testcontainers never reaches a
|
||||
// production binary.
|
||||
//
|
||||
// The estate's CI runs on Kubernetes with no Docker socket, so tests that need
|
||||
// a container must skip themselves under -short. SkipIfShort does exactly that,
|
||||
// CI without a Docker socket runs tests with -short, so tests that need a
|
||||
// container must skip themselves under -short. SkipIfShort does exactly that,
|
||||
// and StartPostgres reports a plain error when no container runtime is
|
||||
// reachable, leaving it to the caller whether that is a skip or a failure.
|
||||
package pgtest
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
// Image is the Postgres the estate targets; every service runs the same major.
|
||||
// Image is the Postgres image the container runs.
|
||||
const Image = "postgres:17-alpine"
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user