Skip to content

Commit dd01484

Browse files
committed
added simple support of testing lanai-cli
1 parent 90340d3 commit dd01484

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

cmd/lanai-cli/cmdutils/global.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Global struct {
4141
TmpDir string `flag:"tmp-dir" desc:"temporary directory."`
4242
OutputDir string `flag:"output,o" desc:"output directory. All non-absolute paths for output are relative to this directory"`
4343
Verbose bool `flag:"debug" desc:"show debug information"`
44+
DryRun bool `flag:"dry-run" desc:"do not actually execute shell commands"`
4445
}
4546

4647
func (g Global) AbsPath(base, path string) string {

cmd/lanai-cli/cmdutils/shell.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func runSingleCommand(ctx context.Context, cmd string, opt *ShCmdOption) (uint8,
149149
logger.WithContext(ctx).Infof("Shell Command: %s", cmd)
150150
}
151151

152+
if GlobalArgs.DryRun {
153+
logger.WithContext(ctx).Infof("Run: %s", cmd)
154+
return 0, nil
155+
}
156+
152157
if e := r.Run(ctx, p); e != nil {
153158
if status, ok := interp.IsExitStatus(err); ok {
154159
return status, e
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package initcmd
2+
3+
import (
4+
"context"
5+
"github.com/cisco-open/go-lanai/cmd/lanai-cli/cmdutils"
6+
"github.com/cisco-open/go-lanai/test"
7+
"github.com/onsi/gomega"
8+
"testing"
9+
)
10+
11+
func TestInstallBinaries(t *testing.T) {
12+
test.RunTest(context.Background(), t,
13+
test.Setup(SetupGlobalArgs()),
14+
test.GomegaSubTest(SubTestWithBinaryOverride(), "WithBinaryOverride"),
15+
)
16+
}
17+
18+
/*************************
19+
Sub-Test Cases
20+
*************************/
21+
22+
func SetupGlobalArgs() test.SetupFunc {
23+
return func(ctx context.Context, t *testing.T) (context.Context, error) {
24+
cmdutils.GlobalArgs.DryRun = true
25+
return ctx, nil
26+
}
27+
}
28+
29+
func SubTestWithBinaryOverride() test.GomegaSubTestFunc {
30+
return func(ctx context.Context, t *testing.T, g *gomega.WithT) {
31+
Module.Binaries = []*Binary{
32+
{
33+
Package: "github.com/golangci/golangci-lint/cmd/golangci-lint",
34+
Version: "",
35+
},
36+
{
37+
Package: "github.com/golangci/golangci-lint/v2/cmd/golangci-lint",
38+
Version: "v2.1.4",
39+
},
40+
{
41+
Package: "",
42+
Version: "v0.0.0",
43+
},
44+
}
45+
e := installBinaries(ctx)
46+
g.Expect(e).To(gomega.Succeed())
47+
}
48+
}

0 commit comments

Comments
 (0)