Skip to content

Commit cf7fb91

Browse files
tbruyelleAlex Johnson
andauthored
test: integration build the ignite binary (#2639)
* test: integration build the ignite binary (WIP) Previously, the ignite binary was supposed to be present in the path, which can be error prone if the binary is not up to date with the integration version. The change builds the binary before the integration are run, using a init() function. This is not very adequate since the binary is not removed at the end of the test. To be able to remove it at the end of the tests we could: 1) add a TestMain in each integration sub-package: not super fan of this because it involves to repeat the same code for each package 2) move all tests in the same package: preferable but delete the separation between the tests. * test: constant ignite binary location Also: - use sync.Once rather than init() func - use gocmd rather than exec.Command directly * chore: no longer need to build the binary in gh action * change cl section Co-authored-by: Alex Johnson <alex@shmeeload.xyz>
1 parent 8df4860 commit cf7fb91

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

.github/workflows/test-integration.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ jobs:
4949
if: env.GIT_DIFF
5050
with:
5151
go-version: 1.19
52-
- name: Install Ignite CLI
53-
if: env.GIT_DIFF
54-
run: go install ./...
5552
- name: Run Integration Tests
5653
if: env.GIT_DIFF
5754
run: go test -v -timeout 60m ./integration/${{ matrix.test-path }}

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Changes
66

7+
- Integration tests build their own ignite binary.
78
- Updated `pkg/cosmosanalysis` to discover the list of app modules when defined in variables.
89
- Switch to broadcast mode sync in `cosmosclient`
910
- Updated `nodetime`: `ts-proto` to `v1.123.0`, `protobufjs` to `v7.1.1`, `swagger-typescript-api` to `v9.2.0`

integration/env.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"flag"
77
"fmt"
88
"os"
9+
"path"
910
"path/filepath"
1011
"strconv"
1112
"strings"
13+
"sync"
1214
"testing"
1315
"time"
1416

@@ -17,17 +19,25 @@ import (
1719

1820
"github.com/ignite/cli/ignite/chainconfig"
1921
"github.com/ignite/cli/ignite/pkg/cosmosfaucet"
22+
"github.com/ignite/cli/ignite/pkg/gocmd"
23+
"github.com/ignite/cli/ignite/pkg/gomodulepath"
2024
"github.com/ignite/cli/ignite/pkg/httpstatuschecker"
21-
"github.com/ignite/cli/ignite/pkg/xexec"
2225
"github.com/ignite/cli/ignite/pkg/xurl"
2326
)
2427

2528
const (
26-
IgniteApp = "ignite"
27-
Stargate = "stargate"
29+
ConfigYML = "config.yml"
2830
)
2931

30-
var isCI, _ = strconv.ParseBool(os.Getenv("CI"))
32+
var (
33+
// IgniteApp hold the location of the ignite binary used in the integration
34+
// tests. The binary is compiled the first time the env.New() function is
35+
// invoked.
36+
IgniteApp = path.Join(os.TempDir(), "ignite-tests", "ignite")
37+
38+
isCI, _ = strconv.ParseBool(os.Getenv("CI"))
39+
compileBinaryOnce sync.Once
40+
)
3141

3242
// Env provides an isolated testing environment and what's needed to
3343
// make it possible.
@@ -44,12 +54,29 @@ func New(t *testing.T) Env {
4454
ctx: ctx,
4555
}
4656
t.Cleanup(cancel)
57+
compileBinaryOnce.Do(func() {
58+
compileBinary(ctx)
59+
})
60+
return e
61+
}
4762

48-
if !xexec.IsCommandAvailable(IgniteApp) {
49-
t.Fatal("ignite needs to be installed")
63+
func compileBinary(ctx context.Context) {
64+
wd, err := os.Getwd()
65+
if err != nil {
66+
panic(fmt.Sprintf("unable to get working dir: %v", err))
67+
}
68+
_, appPath, err := gomodulepath.Find(wd)
69+
if err != nil {
70+
panic(fmt.Sprintf("unable to read go module path: %v", err))
71+
}
72+
var (
73+
output, binary = filepath.Split(IgniteApp)
74+
path = path.Join(appPath, "ignite", "cmd", "ignite")
75+
)
76+
err = gocmd.BuildPath(ctx, output, binary, path, nil)
77+
if err != nil {
78+
panic(fmt.Sprintf("error while building binary: %v", err))
5079
}
51-
52-
return e
5380
}
5481

5582
func (e Env) T() *testing.T {

0 commit comments

Comments
 (0)