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
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ linters:
- varnamelen
- wrapcheck
- wsl # deprecated
- wsl_v5
exclusions:
generated: lax
settings:
Expand Down
56 changes: 56 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Mockery v2 configuration
# See https://vektra.github.io/mockery/latest/configuration/

# Version of mockery to use
version: "2"

# Global configuration
with-expecter: true # Generate expecter interfaces for better type safety
dir: "{{.InterfaceDir}}" # Generate mocks in the same directory as the interface
mockname: "mock{{.InterfaceName}}" # Naming convention: mockInterfaceName
filename: "{{.MockName}}_test.go" # Generate as test files
outpkg: "{{.PackageName}}_test" # Generate in test package
inpackage: false # Don't generate in the same package
testonly: true # Generate in *_test.go files

# Package-specific configurations
packages:
# Auth provider mocks
github.com/EarthBuild/earthbuild/util/llbutil/authprovider:
config:
with-expecter: true
dir: "{{.InterfaceDir}}"
filename: "{{.MockName}}_test.go"
outpkg: "{{.PackageName}}_test"
interfaces:
ProjectAdder:
config:
mockname: "mockProjectAdder"
Child:
config:
mockname: "mockChild"
OS:
config:
mockname: "mockOS"

# Project utilities mocks
github.com/EarthBuild/earthbuild/util/proj:
config:
with-expecter: true
dir: "{{.InterfaceDir}}"
filename: "{{.MockName}}_test.go"
outpkg: "{{.PackageName}}_test"
interfaces:
FS:
config:
mockname: "mockFS"
Cmd:
config:
mockname: "mockCmd"
Execer:
config:
mockname: "mockExecer"

# You can add more packages as needed following the pattern above
# To generate all mocks, run: mockery
# To generate mocks for a specific package: mockery --name=InterfaceName
14 changes: 6 additions & 8 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,13 @@ markdown-spellcheck:
# mocks runs 'go generate' against this module and saves generated mock files
# locally.
mocks:
# renovate: datasource=git packageName=git.sr.ht/~nelsam/hel
ENV hel_version=0.6.6
RUN go install git.sr.ht/~nelsam/hel@v$hel_version
# renovate: datasource=git packageName=golang.org/x/tools/cmd/goimports
ENV goimports_version=0.24.1
RUN go install golang.org/x/tools/cmd/goimports@v$goimports_version
# renovate: datasource=github-releases packageName=vektra/mockery
ENV mockery_version=2.43.2
RUN go install github.com/vektra/mockery/v2@v$mockery_version
COPY --dir +code/earthly /
RUN go generate ./...
FOR mockfile IN $(find . -name 'helheim*_test.go')
COPY .mockery.yaml .
RUN mockery
FOR mockfile IN $(find . -name 'mock*_test.go')
SAVE ARTIFACT $mockfile AS LOCAL $mockfile
END

Expand Down
40 changes: 15 additions & 25 deletions cmd/earthly/subcmd/cmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,19 @@ package subcmd_test
import (
"context"
"fmt"
"strings"
"testing"

"github.com/EarthBuild/earthbuild/cmd/earthly/app"
"github.com/EarthBuild/earthbuild/cmd/earthly/base"
"github.com/EarthBuild/earthbuild/cmd/earthly/subcmd"
"github.com/EarthBuild/earthbuild/conslogging"
"github.com/poy/onpar"
"github.com/poy/onpar/expect"
"github.com/poy/onpar/matchers"
"github.com/urfave/cli/v2"
)

func TestRootCmdsHelp(t *testing.T) {
t.Parallel()

type testCtx struct {
t *testing.T
expect expect.Expectation
}

o := onpar.New()

o.BeforeEach(func(t *testing.T) testCtx {
t.Helper()

return testCtx{
t: t,
expect: expect.New(t),
}
})
defer o.Run(t)

ctx := context.TODO()
newCLI := base.NewCLI(conslogging.ConsoleLogger{},
base.WithVersion(""),
Expand All @@ -49,12 +30,21 @@ func TestRootCmdsHelp(t *testing.T) {

rootCLI := app.BaseCLI.App().Commands

for _, cmd := range checkSubCommands(rootCLI) {
o.Spec(fmt.Sprintf("Help usage for %s should not end with '.'", cmd.Name), func(tt testCtx) {
tt.expect(cmd.Usage).To(matchers.Not(matchers.EndWith(".")))
for _, subCmd := range checkSubCommands(rootCLI) {
t.Run(fmt.Sprintf("Help usage for %s should not end with '.'", subCmd.Name), func(t *testing.T) {
t.Parallel()

if strings.HasSuffix(subCmd.Usage, ".") {
t.Errorf("command %q usage should not end with '.', got: %q", subCmd.Name, subCmd.Usage)
}
})
o.Spec(fmt.Sprintf("Help description for %s should end with '.'", cmd.Name), func(tt testCtx) {
tt.expect(cmd.Description).To(matchers.EndWith("."))

t.Run(fmt.Sprintf("Help description for %s should end with '.'", subCmd.Name), func(t *testing.T) {
t.Parallel()

if !strings.HasSuffix(subCmd.Description, ".") {
t.Errorf("command %q description should end with '.', got: %q", subCmd.Name, subCmd.Description)
}
})
}
}
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.25

require (
al.essio.dev/pkg/shellescape v1.6.0
git.sr.ht/~nelsam/hel v0.9.0
git.sr.ht/~nelsam/hel v0.9.4
github.com/adrg/xdg v0.5.3
github.com/alexcb/binarystream v0.0.0-20231130184431-f2f7a7543c6d
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230219212500-1f9a474cc2dc
Expand Down Expand Up @@ -39,7 +39,6 @@ require (
github.com/opencontainers/image-spec v1.1.1
github.com/otiai10/copy v1.14.1
github.com/pkg/errors v0.9.1
github.com/poy/onpar v1.1.2
github.com/sirupsen/logrus v1.9.4
github.com/stretchr/testify v1.11.1
github.com/tonistiigi/fsutil v0.0.0-20230825212630-f09800878302
Expand All @@ -55,7 +54,7 @@ require (
)

require (
git.sr.ht/~nelsam/correct v0.1.1 // indirect
git.sr.ht/~nelsam/correct v0.1.2 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.11.7 // indirect
Expand Down Expand Up @@ -106,10 +105,12 @@ require (
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/poy/onpar v0.3.5 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea // indirect
github.com/tonistiigi/vt100 v0.0.0-20230623042737-f9a4f7ef6531 // indirect
github.com/vbatts/tar-split v0.11.3 // indirect
Expand Down
Loading
Loading