Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.62.0
GOLANGCI_LINT_VERSION: v2.3.0
CGO_ENABLED: 0

steps:
Expand Down
124 changes: 66 additions & 58 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
version: "2"

run:
timeout: 10m

linters-settings:
govet:
enable-all: true
disable:
- fieldalignment
gocyclo:
min-complexity: 15
goconst:
min-len: 5
min-occurrences: 3
misspell:
locale: US
funlen:
lines: -1
statements: 50
godox:
keywords:
- FIXME
gofumpt:
extra-rules: true
depguard:
rules:
main:
deny:
- pkg: "github.com/instana/testify"
desc: not allowed
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- sloppyReassign
- rangeValCopy
- octalLiteral
- paramTypeCombine # already handle by gofumpt.extra-rules
- unnamedResult
- hugeParam
tagliatelle:
case:
linters:
settings:
govet:
enable-all: true
disable:
- fieldalignment
gocyclo:
min-complexity: 15
goconst:
min-len: 5
min-occurrences: 3
misspell:
locale: US
funlen:
lines: -1
statements: 50
godox:
keywords:
- FIXME
depguard:
rules:
json: pascal
gosec:
excludes:
- G304
- G306
main:
deny:
- pkg: "github.com/instana/testify"
desc: not allowed
- pkg: "github.com/pkg/errors"
desc: Should be replaced by standard lib errors package
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- sloppyReassign
- rangeValCopy
- octalLiteral
- paramTypeCombine # already handle by gofumpt.extra-rules
- unnamedResult
- hugeParam
tagliatelle:
case:
rules:
json: pascal
gosec:
excludes:
- G304
- G306

linters:
enable-all: true
default: all
disable:
- exportloopref # deprecated
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- cyclop # duplicate of gocyclo
- lll
- dupl
- wsl
- wsl_v5
- nlreturn
- mnd
- err113
Expand All @@ -78,17 +78,25 @@ linters:
- errchkjson
- contextcheck

exclusions:
warn-unused: true
rules:
- text: fmt.Sprintf can be replaced with string
linters:
- perfsprint

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude:
- 'fmt.Sprintf can be replaced with string'
exclude-rules:
- path: .*_test.go
linters:
- funlen
- noctx

formatters:
enable:
- gci
- gofumpt

settings:
gofumpt:
extra-rules: true

output:
show-stats: true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
default: clean lint test build

lint:
golangci-lint run
go run github.com/golangci/golangci-lint/v2/cmd/[email protected] run

clean:
rm -rf cover.out
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/traefik/mocktail

go 1.23.0
go 1.24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
go 1.24
go 1.24.0


require (
github.com/ettle/strcase v0.2.0
Expand Down
5 changes: 4 additions & 1 deletion mocktail.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
import (
"bufio"
"bytes"
"context"
"flag"
"fmt"
"go/format"
Expand Down Expand Up @@ -42,7 +43,9 @@ type InterfaceDesc struct {
}

func main() {
info, err := getModuleInfo(os.Getenv("MOCKTAIL_TEST_PATH"))
ctx := context.Background()

info, err := getModuleInfo(ctx, os.Getenv("MOCKTAIL_TEST_PATH"))
if err != nil {
log.Fatal("get module path", err)
}
Expand Down
8 changes: 4 additions & 4 deletions mocktail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestMocktail(t *testing.T) {

t.Setenv("MOCKTAIL_TEST_PATH", filepath.Join(testRoot, entry.Name()))

output, err := exec.Command("go", "run", ".").CombinedOutput()
output, err := exec.CommandContext(t.Context(), "go", "run", ".").CombinedOutput()
t.Log(string(output))

require.NoError(t, err)
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestMocktail(t *testing.T) {
continue
}

cmd := exec.Command("go", "test", "-v", "./...")
cmd := exec.CommandContext(t.Context(), "go", "test", "-v", "./...")
cmd.Dir = filepath.Join(testRoot, entry.Name())

output, err := cmd.CombinedOutput()
Expand All @@ -88,7 +88,7 @@ func TestMocktail_exported(t *testing.T) {

t.Setenv("MOCKTAIL_TEST_PATH", filepath.Join(testRoot, entry.Name()))

output, err := exec.Command("go", "run", ".", "-e").CombinedOutput()
output, err := exec.CommandContext(t.Context(), "go", "run", ".", "-e").CombinedOutput()
t.Log(string(output))

require.NoError(t, err)
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestMocktail_exported(t *testing.T) {
continue
}

cmd := exec.Command("go", "test", "-v", "./...")
cmd := exec.CommandContext(t.Context(), "go", "test", "-v", "./...")
cmd.Dir = filepath.Join(testRoot, entry.Name())

output, err := cmd.CombinedOutput()
Expand Down
5 changes: 3 additions & 2 deletions mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -16,9 +17,9 @@ type modInfo struct {
Main bool `json:"Main"`
}

func getModuleInfo(dir string) (modInfo, error) {
func getModuleInfo(ctx context.Context, dir string) (modInfo, error) {
// https://github.com/golang/go/issues/44753#issuecomment-790089020
cmd := exec.Command("go", "list", "-m", "-json")
cmd := exec.CommandContext(ctx, "go", "list", "-m", "-json")
if dir != "" {
cmd.Dir = dir
}
Expand Down
60 changes: 30 additions & 30 deletions syrup.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ type Syrup struct {
Signature *types.Signature
}

// Call generates mock.Call wrapper.
func (s Syrup) Call(writer io.Writer, methods []*types.Func) error {
err := s.callBase(writer)
if err != nil {
return err
}

err = s.typedReturns(writer)
if err != nil {
return err
}

err = s.returnsFn(writer)
if err != nil {
return err
}

err = s.typedRun(writer)
if err != nil {
return err
}

err = s.callMethodsOn(writer, methods)
if err != nil {
return err
}

return s.callMethodOnRaw(writer, methods)
}

// MockMethod generates method mocks.
func (s Syrup) MockMethod(writer io.Writer) error {
err := s.mockedMethod(writer)
Expand Down Expand Up @@ -312,36 +342,6 @@ func (s Syrup) methodOnRaw(writer io.Writer) error {
return w.Err()
}

// Call generates mock.Call wrapper.
func (s Syrup) Call(writer io.Writer, methods []*types.Func) error {
err := s.callBase(writer)
if err != nil {
return err
}

err = s.typedReturns(writer)
if err != nil {
return err
}

err = s.returnsFn(writer)
if err != nil {
return err
}

err = s.typedRun(writer)
if err != nil {
return err
}

err = s.callMethodsOn(writer, methods)
if err != nil {
return err
}

return s.callMethodOnRaw(writer, methods)
}

func (s Syrup) callBase(writer io.Writer) error {
base := template.New("templateCallBase").Funcs(template.FuncMap{
"ToGoCamel": strcase.ToGoCamel,
Expand Down
Loading