mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
ci: pin golangci-lint 2.14, add -race, fix golden updates (#674)
Local v2.14 and CI v2.10 disagreed on gofumpt; extra.group-params keeps v2.10's rules exactly. go test ./... -update failed in the 12 packages that never import golden, so it is HBD_UPDATE_GOLDEN=1 now.
This commit is contained in:
1 parent
ed736496fc
commit
6d6191b4c6
6 files changed
+16
-16
No files matched your search
@@ -40,4 +40,4 @@ jobs:
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
version: v2.10
|
||||
version: v2.14
|
||||
@@ -29,9 +29,9 @@ jobs:
|
||||
if: matrix.os == 'windows-latest'
|
||||
run: go test -v ./...
|
||||
|
||||
- name: Run tests with coverage
|
||||
- name: Run tests with race detector and coverage
|
||||
if: matrix.os != 'windows-latest'
|
||||
run: go test -v -coverprofile=coverage.out ./...
|
||||
run: go test -v -race -coverprofile=coverage.out ./...
|
||||
|
||||
- name: Upload coverage
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
|
||||
+4
-5
@@ -59,8 +59,9 @@ linters:
|
||||
- gocognit
|
||||
- nestif
|
||||
|
||||
# Note: copyloopvar, intrange, modernize, perfsprint require Go 1.22+
|
||||
# Note: copyloopvar, intrange, modernize require Go 1.22+
|
||||
# They will be enabled when Go version constraint is lifted.
|
||||
# perfsprint has no Go version floor; it stays off for now, as its findings are mechanical errors.New swaps.
|
||||
|
||||
settings:
|
||||
depguard:
|
||||
@@ -194,9 +195,6 @@ linters:
|
||||
- text: "SELECT"
|
||||
linters:
|
||||
- gosec
|
||||
- path: "cmd/hack-browser-data/main.go"
|
||||
linters:
|
||||
- lll
|
||||
- path: "masterkey/gcoredump_darwin.go"
|
||||
linters:
|
||||
- gocognit
|
||||
@@ -210,7 +208,8 @@ formatters:
|
||||
- goimports
|
||||
settings:
|
||||
gofumpt:
|
||||
extra-rules: true
|
||||
extra:
|
||||
group-params: true
|
||||
goimports:
|
||||
local-prefixes:
|
||||
- github.com/moond4rk/hackbrowserdata
|
||||
@@ -61,7 +61,7 @@ make payload-clean # rm internal/abe/payload/*.bin
|
||||
- **Logging**: `log.Debugf` for record-level diagnostics, `log.Infof` for user-facing progress/status, `log.Warnf` for unexpected conditions. Extract methods should return errors, not log them.
|
||||
- **Naming**: follow Go conventions and the settled names in `rfcs/004-naming-decisions.md` — `Def` not `BrowserConfig`, `Extract` not `BrowsingData`
|
||||
- **Comment width**: wrap comments at 140 columns (matches `.golangci.yml` `lll.line-length`)
|
||||
- **Tests**: `internal/browser/browsertest` builds real fixture files (SQLite, JSON, LevelDB, plist) into a `t.TempDir()` — never a live browser, never a database mock; goldens live in each package's `testdata/` and `go test ./... -update` regenerates them
|
||||
- **Tests**: `internal/browser/browsertest` builds real fixture files (SQLite, JSON, LevelDB, plist) into a `t.TempDir()` — never a live browser, never a database mock; goldens live in each package's `testdata/` and `HBD_UPDATE_GOLDEN=1 go test ./...` regenerates them
|
||||
- **Architecture**: see `rfcs/README.md` — design RFCs 000–011, format and technique RFCs 013–021
|
||||
|
||||
## Key Constraints
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Package golden compares test output against files in the calling package's testdata/, which -update rewrites.
|
||||
// Package golden compares test output against files in the calling package's testdata/, which HBD_UPDATE_GOLDEN=1 rewrites.
|
||||
package golden
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -15,21 +14,23 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var update = flag.Bool("update", false, "rewrite the golden files from the current code")
|
||||
// updateEnv is an environment variable, not a test flag: go test ./... passes a flag to packages that do not define it,
|
||||
// and reading the variable at test time keys go test's cache on it.
|
||||
const updateEnv = "HBD_UPDATE_GOLDEN"
|
||||
|
||||
const dir = "testdata"
|
||||
|
||||
// Assert compares got with testdata/<name>, rewriting it first when -update is set.
|
||||
// Assert compares got with testdata/<name>, rewriting it first when HBD_UPDATE_GOLDEN=1.
|
||||
func Assert(t testing.TB, name, got string) {
|
||||
t.Helper()
|
||||
path := filepath.Join(dir, name)
|
||||
if *update {
|
||||
if os.Getenv(updateEnv) == "1" {
|
||||
require.NoError(t, os.MkdirAll(dir, 0o755))
|
||||
require.NoError(t, os.WriteFile(path, []byte(got), 0o644))
|
||||
}
|
||||
want, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, string(want), got, "regenerate with: go test ./... -run '%s' -update", t.Name())
|
||||
assert.Equal(t, string(want), got, "regenerate with: %s=1 go test ./... -run '%s'", updateEnv, t.Name())
|
||||
}
|
||||
|
||||
// Read returns testdata/<name>.
|
||||
|
||||
@@ -29,7 +29,7 @@ These guard the contract; a failure means something a user can see has changed.
|
||||
|
||||
## Golden files
|
||||
|
||||
Export and extractor tests compare against checked-in golden outputs. Deterministic ordering is what makes goldens stable — without it, goldens would flap. A `-update` flag regenerates them on intentional changes. Goldens double as documentation of the exact output shape, useful for the README and for talks.
|
||||
Export and extractor tests compare against checked-in golden outputs. Deterministic ordering is what makes goldens stable — without it, goldens would flap. Setting `HBD_UPDATE_GOLDEN=1` regenerates them on intentional changes. Goldens double as documentation of the exact output shape, useful for the README and for talks.
|
||||
|
||||
Each golden lives beside the package whose output it pins: the export goldens in `export`, `keys.json` in `masterkey`, and the `extract`, `archive`, and `restore` goldens — all of which run the pipeline — in `app`; the flag-surface and `list` goldens stay in `cmd/hack-browser-data`. Shared fixture builders are in `internal/browser/browsertest`, the comparison helpers in `internal/golden`. A golden holds what no other golden already implies: the Cookie-Editor golden holds only `cookie.json`, because every other category is asserted to match the json output byte for byte, and `restore` is asserted to match the extract output except for its `browser` stamp.
|
||||
|
||||
|
||||
Reference in new issue
Block a user