Skip to content

Commit 33a8dfa

Browse files
committed
Replace deprecated RunMain in integration tests
Also moved the cmd package under internal. Now that a return int is no longer required, it would be nice to remove that package completely and use the cmd main methods directly but I'm not sure how! Signed-off-by: James Taylor <[email protected]>
1 parent 4a87af1 commit 33a8dfa

File tree

9 files changed

+31
-48
lines changed

9 files changed

+31
-48
lines changed

cmd/build/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
package main
44

5-
import (
6-
"os"
7-
8-
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
9-
)
5+
import "github.com/hyperledger-labs/fabric-builder-k8s/internal/cmd"
106

117
func main() {
12-
os.Exit(cmd.Build())
8+
cmd.Build()
139
}

cmd/detect/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
package main
44

5-
import (
6-
"os"
7-
8-
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
9-
)
5+
import "github.com/hyperledger-labs/fabric-builder-k8s/internal/cmd"
106

117
func main() {
12-
os.Exit(cmd.Detect())
8+
cmd.Detect()
139
}

cmd/release/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
package main
44

5-
import (
6-
"os"
7-
8-
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
9-
)
5+
import "github.com/hyperledger-labs/fabric-builder-k8s/internal/cmd"
106

117
func main() {
12-
os.Exit(cmd.Release())
8+
cmd.Release()
139
}

cmd/run/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
package main
44

5-
import (
6-
"os"
7-
8-
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
9-
)
5+
import "github.com/hyperledger-labs/fabric-builder-k8s/internal/cmd"
106

117
func main() {
12-
os.Exit(cmd.Run())
8+
cmd.Run()
139
}

cmd/build.go renamed to internal/cmd/build.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
1313
)
1414

15-
func Build() int {
15+
func Build() {
1616
const (
1717
expectedArgsLength = 4
1818
chaincodeSourceDirectoryArg = 1
@@ -29,7 +29,7 @@ func Build() int {
2929
"Expected CHAINCODE_SOURCE_DIR, CHAINCODE_METADATA_DIR and BUILD_OUTPUT_DIR arguments",
3030
)
3131

32-
return 1
32+
os.Exit(1)
3333
}
3434

3535
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
@@ -49,8 +49,8 @@ func Build() int {
4949
if err := build.Run(ctx); err != nil {
5050
logger.Printf("Error building chaincode: %+v", err)
5151

52-
return 1
52+
os.Exit(1)
5353
}
5454

55-
return 0
55+
os.Exit(0)
5656
}

cmd/detect.go renamed to internal/cmd/detect.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
1414
)
1515

16-
func Detect() int {
16+
func Detect() {
1717
const (
1818
expectedArgsLength = 3
1919
chaincodeSourceDirectoryArg = 1
@@ -27,7 +27,7 @@ func Detect() int {
2727
if len(os.Args) != expectedArgsLength {
2828
logger.Println("Expected CHAINCODE_SOURCE_DIR and CHAINCODE_METADATA_DIR arguments")
2929

30-
return 1
30+
os.Exit(1)
3131
}
3232

3333
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
@@ -47,8 +47,8 @@ func Detect() int {
4747
logger.Printf("Error detecting chaincode: %+v", err)
4848
}
4949

50-
return 1
50+
os.Exit(1)
5151
}
5252

53-
return 0
53+
os.Exit(0)
5454
}

cmd/release.go renamed to internal/cmd/release.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
1313
)
1414

15-
func Release() int {
15+
func Release() {
1616
const (
1717
expectedArgsLength = 3
1818
buildOutputDirectoryArg = 1
@@ -26,7 +26,7 @@ func Release() int {
2626
if len(os.Args) != expectedArgsLength {
2727
logger.Println("Expected BUILD_OUTPUT_DIR and RELEASE_OUTPUT_DIR arguments")
2828

29-
return 1
29+
os.Exit(1)
3030
}
3131

3232
buildOutputDirectory := os.Args[buildOutputDirectoryArg]
@@ -43,8 +43,8 @@ func Release() int {
4343
if err := release.Run(ctx); err != nil {
4444
logger.Printf("Error releasing chaincode: %+v", err)
4545

46-
return 1
46+
os.Exit(1)
4747
}
4848

49-
return 0
49+
os.Exit(0)
5050
}

cmd/run.go renamed to internal/cmd/run.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func getChaincodeStartTimeout(logger *log.CmdLogger) (chaincodeStartTimeoutDurat
113113
return chaincodeStartTimeoutDuration, true
114114
}
115115

116-
func Run() int {
116+
func Run() {
117117
const (
118118
expectedArgsLength = 3
119119
buildOutputDirectoryArg = 1
@@ -127,7 +127,7 @@ func Run() int {
127127
if len(os.Args) != expectedArgsLength {
128128
logger.Println("Expected BUILD_OUTPUT_DIR and RUN_METADATA_DIR arguments")
129129

130-
return 1
130+
os.Exit(1)
131131
}
132132

133133
buildOutputDirectory := os.Args[buildOutputDirectoryArg]
@@ -141,27 +141,27 @@ func Run() int {
141141

142142
peerID, ok := getPeerID(logger)
143143
if !ok {
144-
return 1
144+
os.Exit(1)
145145
}
146146

147147
kubeconfigPath := getKubeconfigPath(logger)
148148
kubeNamespace := getKubeNamespace(logger)
149149

150150
kubeNodeRole, ok := getKubeNodeRole(logger)
151151
if !ok {
152-
return 1
152+
os.Exit(1)
153153
}
154154

155155
kubeServiceAccount := getKubeServiceAccount(logger)
156156

157157
kubeNamePrefix, ok := getKubeNamePrefix(logger)
158158
if !ok {
159-
return 1
159+
os.Exit(1)
160160
}
161161

162162
chaincodeStartTimeout, ok := getChaincodeStartTimeout(logger)
163163
if !ok {
164-
return 1
164+
os.Exit(1)
165165
}
166166

167167
run := &builder.Run{
@@ -179,8 +179,8 @@ func Run() int {
179179
if err := run.Run(ctx); err != nil {
180180
logger.Printf("Error running chaincode: %+v", err)
181181

182-
return 1
182+
os.Exit(1)
183183
}
184184

185-
return 0
185+
os.Exit(0)
186186
}

test/integration/main_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ package integration_test
88
import (
99
"context"
1010
"fmt"
11-
"os"
1211
"testing"
1312

14-
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
13+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/cmd"
1514
"github.com/hyperledger-labs/fabric-builder-k8s/test"
1615
"github.com/rogpeppe/go-internal/testscript"
1716
batchv1 "k8s.io/api/batch/v1"
@@ -71,7 +70,7 @@ func TestMain(m *testing.M) {
7170
})
7271

7372
wm := test.NewWrappedM(m, testenv)
74-
os.Exit(testscript.RunMain(wm, map[string]func() int{
73+
testscript.Main(wm, map[string]func(){
7574
"run": cmd.Run,
76-
}))
75+
})
7776
}

0 commit comments

Comments
 (0)