Skip to content

Commit

Permalink
chore: Go version bump and other maintenance chores (#46)
Browse files Browse the repository at this point in the history
- Introduce a Makefile for easier consistent usage of tools (mainly the
  linter) locally and in CI
- Add an `Assert` (no `f` suffix), since `go vet` has started
  complaining about that.
- Bump project Go version
- Bump GitHub actions versions
- Address new lint violations
  • Loading branch information
kinbiko authored Oct 3, 2024
1 parent a89c7b6 commit 6891287
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 34 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,22 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.17
uses: actions/setup-go@v1
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.17
go-version: 1.22
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: go get -v -t -d ./...

- name: Build
run: go build -v .
uses: actions/checkout@v4

- name: Test (race)
run: go test -race -v -coverprofile=profile.cov -covermode=atomic ./...
run: make coverage

- name: Coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov

- name: Install Linter
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.45.2

- name: Lint
run: ./bin/golangci-lint run .
run: make lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
*.out

tags

bin/
10 changes: 2 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ linters-settings:

govet:
# report about shadowed variables
check-shadowing: true
shadow: true

# enable or disable analyzers by name
# enable:
Expand Down Expand Up @@ -151,12 +151,6 @@ linters:

- depguard

# These are apparently deprecated but still yell at you if you don't disable them
- golint
- scopelint
- maligned
- interfacer

- gci # This conflicts with goimports
- varnamelen # This has too many false positives around indexes etc to be useful
presets:
Expand Down Expand Up @@ -191,7 +185,7 @@ issues:
- maintidx
- path: \.go
linters:
- goerr113
- err113

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
Expand Down
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
LINTER_VERSION := v1.61.0

.PHONY: check
check: lint test

.PHONY: get-deps
get-deps:
go get -v -t -d ./...

.PHONY: lint
lint: ./bin/linter
./bin/linter run ./...

.PHONY: test
test:
go test -race -count=1 ./...

.PHONY: coverage
coverage:
go test -race -v -coverprofile=profile.cov -covermode=atomic ./...

bin/linter: Makefile
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin $(LINTER_VERSION)
mv ./bin/golangci-lint ./bin/linter
7 changes: 7 additions & 0 deletions exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ func (a *Asserter) Assertf(actualJSON, expectedJSON string, fmtArgs ...interface
a.tt.Helper()
a.pathassertf("$", actualJSON, fmt.Sprintf(expectedJSON, fmtArgs...))
}

// Assert works like Assertf, but does not accept fmt.Sprintf directives.
// See Assert for details.
func (a *Asserter) Assert(actualJSON, expectedJSON string) {
a.tt.Helper()
a.pathassertf("$", actualJSON, expectedJSON)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/kinbiko/jsonassert

go 1.19
go 1.22
11 changes: 1 addition & 10 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func TestAssertf(t *testing.T) {
"negative floats": {`-12.345`, `-12.345`, nil},
"strings": {`"hello world"`, `"hello world"`, nil},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand All @@ -44,7 +43,6 @@ func TestAssertf(t *testing.T) {
"strings": {`"hello"`, `"world"`, []string{`expected string at '$' to be 'world' but was 'hello'`}},
"empty v non-empty string": {`""`, `"world"`, []string{`expected string at '$' to be 'world' but was ''`}},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -82,7 +80,6 @@ func TestAssertf(t *testing.T) {
},
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -112,7 +109,6 @@ func TestAssertf(t *testing.T) {
},
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -151,7 +147,6 @@ func TestAssertf(t *testing.T) {
nil,
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -205,7 +200,6 @@ but expected JSON was:
},
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -247,7 +241,6 @@ but expected JSON was:
},
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -313,7 +306,6 @@ but expected JSON was:
nil,
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -345,7 +337,6 @@ potentially in a different order`,
},
},
} {
tc := tc
t.Run(name, func(t *testing.T) { tc.check(t) })
}
})
Expand Down Expand Up @@ -461,7 +452,7 @@ type testCase struct {
func (tc *testCase) check(t *testing.T) {
t.Helper()
tp := &testPrinter{messages: nil}
jsonassert.New(tp).Assertf(tc.act, tc.exp)
jsonassert.New(tp).Assert(tc.act, tc.exp)

if got := len(tp.messages); got != len(tc.msgs) {
t.Errorf("expected %d assertion message(s) but got %d", len(tc.msgs), got)
Expand Down

0 comments on commit 6891287

Please sign in to comment.