Skip to content

Commit 99feafe

Browse files
authored
Change cmg -testify flag to use assert.TestingT (#639)
When the -testify flag is used, mock constructors now accept assert.TestingT instead of *testing.T, providing better flexibility for testing with custom test harnesses. Also update the minimum Go version requirement from 1.21 to 1.24 in GitHub Actions workflows and README.
1 parent 3ec4756 commit 99feafe

File tree

7 files changed

+84
-10
lines changed

7 files changed

+84
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v6
1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: "1.21"
17+
go-version: "1.24"
1818
- name: tests
1919
run: scripts/cibuild
2020
- name: Upload coverage to Codecov

.github/workflows/integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v6
1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: "1.21"
17+
go-version: "1.24"
1818
- name: tests
1919
run: |
2020
check_service_health() {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ debug and operate microservices using Clue's instrumentation capabilities.
7878

7979
## Installation
8080

81-
Clue requires Go 1.21 or later. Install the packages required for your
81+
Clue requires Go 1.24 or later. Install the packages required for your
8282
application using `go get`, for example:
8383

8484
```bash

go.work.sum

Lines changed: 70 additions & 0 deletions
Large diffs are not rendered by default.

mock/cmd/cmg/pkg/generate/_tests/testify/mocks/testify.go

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mock/cmd/cmg/pkg/generate/mocks.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ var (
6060
// If testify is true, it uses github.com/stretchr/testify for assertions.
6161
func NewMocks(prefix string, p parse.Package, interfaces []parse.Interface, toolVersionFunc ToolVersionFunc, testify bool) Mocks {
6262
var (
63-
stdImports = importMap{"testing": newImport("testing")}
63+
stdImports = make(importMap)
6464
extImports = importMap{"mock": newImport("goa.design/clue/mock")}
6565
intImports = make(importMap)
6666
)
6767
if testify {
6868
extImports["assert"] = newImport("github.com/stretchr/testify/assert")
69+
} else {
70+
stdImports["testing"] = newImport("testing")
6971
}
7072

7173
var (

mock/cmd/cmg/pkg/generate/mocks.go.tmpl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import (
99
{{- range .StdImports }}
1010
{{ if .Alias }}{{ .Alias }} {{ end }}"{{ .PkgPath }}"
1111
{{- end }}
12-
{{ range .ExtImports }}
12+
{{- if and (gt (len .StdImports) 0) (or (gt (len .ExtImports) 0) (gt (len .IntImports) 0)) }}
13+
{{ end }}
14+
{{- range .ExtImports }}
1315
{{ if .Alias }}{{ .Alias }} {{ end }}"{{ .PkgPath }}"
1416
{{- end }}
15-
{{ range .IntImports }}
17+
{{- if and (gt (len .ExtImports) 0) (gt (len .IntImports) 0) }}
18+
{{ end }}
19+
{{- range .IntImports }}
1620
{{ if .Alias }}{{ .Alias }} {{ end }}"{{ .PkgPath }}"
1721
{{- end }}
1822
)
@@ -40,7 +44,7 @@ type (
4044
{{- range $index, $interface := .Interfaces }}
4145
{{- if ge $index 1 }}
4246
{{ end }}
43-
func {{ .Constructor }}{{ .TypeParameters }}(t *testing.T) *{{ .Name }}{{ .TypeParameterVars }} {
47+
func {{ .Constructor }}{{ .TypeParameters }}(t {{ if $testify }}assert.TestingT{{ else }}*testing.T{{ end }}) *{{ .Name }}{{ .TypeParameterVars }} {
4448
var (
4549
{{ .Var | printf ($import.AliasOrPkgName | .ConstructorFmt) }} = &{{ .Name }}{{ .TypeParameterVars }}{mock.New(), {{ if $testify }}assert.New(t){{ else }}t{{ end }}}
4650
_ {{ $import.AliasOrPkgName }}.{{ .Name }}{{ .TypeParameterVars }} = m

0 commit comments

Comments
 (0)