Skip to content

Commit 53db654

Browse files
committed
Improve integration tests
Use github.com/rogpeppe/go-internal/testscript and github.com/kubernetes-sigs/e2e-framework to test the builder run command with a kind kubernetes cluster New integration tests should now be easier to add, e.g. for #228 Signed-off-by: James Taylor <[email protected]>
1 parent c3b73a8 commit 53db654

File tree

21 files changed

+819
-317
lines changed

21 files changed

+819
-317
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ jobs:
4444
run: go test -v ./...
4545
env:
4646
FABRIC_K8S_BUILDER_DEBUG: 'true'
47-
INCLUDE_KIND_TESTS: ${{ matrix.os == 'ubuntu-latest' && 'true' || 'false' }}
4847

4948
- name: Package
5049
run: |

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ jobs:
2828
go-version: 1.22
2929
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
3030
- name: golangci-lint
31-
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
31+
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
3232
with:
33-
version: v1.56.2
33+
version: v1.62

.golangci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ linters:
88
- bodyclose
99
- containedctx
1010
- contextcheck
11+
- copyloopvar
1112
- cyclop
1213
- decorder
1314
- dogsled
@@ -17,9 +18,7 @@ linters:
1718
- errchkjson
1819
- errname
1920
- errorlint
20-
- execinquery
2121
- exhaustive
22-
- exportloopref
2322
- forbidigo
2423
- forcetypeassert
2524
- funlen
@@ -35,7 +34,6 @@ linters:
3534
- gofumpt
3635
- goheader
3736
- goimports
38-
- gomnd
3937
- gomoddirectives
4038
- gomodguard
4139
- goprintffuncname
@@ -49,6 +47,7 @@ linters:
4947
- maintidx
5048
- makezero
5149
- misspell
50+
- mnd
5251
- nakedret
5352
- nestif
5453
- nilerr

cmd/build.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"os"
8+
"strconv"
9+
10+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
11+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
12+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
13+
)
14+
15+
func Build() int {
16+
const (
17+
expectedArgsLength = 4
18+
chaincodeSourceDirectoryArg = 1
19+
chaincodeMetadataDirectoryArg = 2
20+
buildOutputDirectoryArg = 3
21+
)
22+
23+
debug, _ := strconv.ParseBool(util.GetOptionalEnv(util.DebugVariable, "false"))
24+
ctx := log.NewCmdContext(context.Background(), debug)
25+
logger := log.New(ctx)
26+
27+
if len(os.Args) != expectedArgsLength {
28+
logger.Println(
29+
"Expected CHAINCODE_SOURCE_DIR, CHAINCODE_METADATA_DIR and BUILD_OUTPUT_DIR arguments",
30+
)
31+
32+
return 1
33+
}
34+
35+
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
36+
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]
37+
buildOutputDirectory := os.Args[buildOutputDirectoryArg]
38+
39+
logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
40+
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)
41+
logger.Debugf("Build output directory: %s", buildOutputDirectory)
42+
43+
build := &builder.Build{
44+
ChaincodeSourceDirectory: chaincodeSourceDirectory,
45+
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
46+
BuildOutputDirectory: buildOutputDirectory,
47+
}
48+
49+
if err := build.Run(ctx); err != nil {
50+
logger.Printf("Error building chaincode: %+v", err)
51+
52+
return 1
53+
}
54+
55+
return 0
56+
}

cmd/build/main.go

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,11 @@
33
package main
44

55
import (
6-
"context"
76
"os"
87

9-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
10-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
11-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
12-
)
13-
14-
const (
15-
expectedArgsLength = 4
16-
chaincodeSourceDirectoryArg = 1
17-
chaincodeMetadataDirectoryArg = 2
18-
buildOutputDirectoryArg = 3
8+
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
199
)
2010

2111
func main() {
22-
debug := util.GetOptionalEnv(util.DebugVariable, "false")
23-
ctx := log.NewCmdContext(context.Background(), debug == "true")
24-
logger := log.New(ctx)
25-
26-
if len(os.Args) != expectedArgsLength {
27-
logger.Println(
28-
"Expected CHAINCODE_SOURCE_DIR, CHAINCODE_METADATA_DIR and BUILD_OUTPUT_DIR arguments",
29-
)
30-
os.Exit(1)
31-
}
32-
33-
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
34-
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]
35-
buildOutputDirectory := os.Args[buildOutputDirectoryArg]
36-
37-
logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
38-
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)
39-
logger.Debugf("Build output directory: %s", buildOutputDirectory)
40-
41-
build := &builder.Build{
42-
ChaincodeSourceDirectory: chaincodeSourceDirectory,
43-
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
44-
BuildOutputDirectory: buildOutputDirectory,
45-
}
46-
47-
if err := build.Run(ctx); err != nil {
48-
logger.Printf("Error building chaincode: %+v", err)
49-
os.Exit(1)
50-
}
12+
os.Exit(cmd.Build())
5113
}

cmd/detect.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"errors"
8+
"os"
9+
"strconv"
10+
11+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
12+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
13+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
14+
)
15+
16+
func Detect() int {
17+
const (
18+
expectedArgsLength = 3
19+
chaincodeSourceDirectoryArg = 1
20+
chaincodeMetadataDirectoryArg = 2
21+
)
22+
23+
debug, _ := strconv.ParseBool(util.GetOptionalEnv(util.DebugVariable, "false"))
24+
ctx := log.NewCmdContext(context.Background(), debug)
25+
logger := log.New(ctx)
26+
27+
if len(os.Args) != expectedArgsLength {
28+
logger.Println("Expected CHAINCODE_SOURCE_DIR and CHAINCODE_METADATA_DIR arguments")
29+
30+
return 1
31+
}
32+
33+
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
34+
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]
35+
36+
logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
37+
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)
38+
39+
detect := &builder.Detect{
40+
ChaincodeSourceDirectory: chaincodeSourceDirectory,
41+
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
42+
}
43+
44+
if err := detect.Run(ctx); err != nil {
45+
if !errors.Is(err, builder.ErrUnsupportedChaincodeType) {
46+
// don't spam the peer log if it's just chaincode we don't recognise
47+
logger.Printf("Error detecting chaincode: %+v", err)
48+
}
49+
50+
return 1
51+
}
52+
53+
return 0
54+
}

cmd/detect/main.go

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,11 @@
33
package main
44

55
import (
6-
"context"
7-
"errors"
86
"os"
97

10-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
11-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
12-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
13-
)
14-
15-
const (
16-
expectedArgsLength = 3
17-
chaincodeSourceDirectoryArg = 1
18-
chaincodeMetadataDirectoryArg = 2
8+
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
199
)
2010

2111
func main() {
22-
debug := util.GetOptionalEnv(util.DebugVariable, "false")
23-
ctx := log.NewCmdContext(context.Background(), debug == "true")
24-
logger := log.New(ctx)
25-
26-
if len(os.Args) != expectedArgsLength {
27-
logger.Println("Expected CHAINCODE_SOURCE_DIR and CHAINCODE_METADATA_DIR arguments")
28-
os.Exit(1)
29-
}
30-
31-
chaincodeSourceDirectory := os.Args[chaincodeSourceDirectoryArg]
32-
chaincodeMetadataDirectory := os.Args[chaincodeMetadataDirectoryArg]
33-
34-
logger.Debugf("Chaincode source directory: %s", chaincodeSourceDirectory)
35-
logger.Debugf("Chaincode metadata directory: %s", chaincodeMetadataDirectory)
36-
37-
detect := &builder.Detect{
38-
ChaincodeSourceDirectory: chaincodeSourceDirectory,
39-
ChaincodeMetadataDirectory: chaincodeMetadataDirectory,
40-
}
41-
42-
if err := detect.Run(ctx); err != nil {
43-
if !errors.Is(err, builder.ErrUnsupportedChaincodeType) {
44-
// don't spam the peer log if it's just chaincode we don't recognise
45-
logger.Printf("Error detecting chaincode: %+v", err)
46-
}
47-
48-
os.Exit(1)
49-
}
12+
os.Exit(cmd.Detect())
5013
}

cmd/release.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"os"
8+
"strconv"
9+
10+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
11+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
12+
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
13+
)
14+
15+
func Release() int {
16+
const (
17+
expectedArgsLength = 3
18+
buildOutputDirectoryArg = 1
19+
releaseOutputDirectoryArg = 2
20+
)
21+
22+
debug, _ := strconv.ParseBool(util.GetOptionalEnv(util.DebugVariable, "false"))
23+
ctx := log.NewCmdContext(context.Background(), debug)
24+
logger := log.New(ctx)
25+
26+
if len(os.Args) != expectedArgsLength {
27+
logger.Println("Expected BUILD_OUTPUT_DIR and RELEASE_OUTPUT_DIR arguments")
28+
29+
return 1
30+
}
31+
32+
buildOutputDirectory := os.Args[buildOutputDirectoryArg]
33+
releaseOutputDirectory := os.Args[releaseOutputDirectoryArg]
34+
35+
logger.Debugf("Build output directory: %s", buildOutputDirectory)
36+
logger.Debugf("Release output directory: %s", releaseOutputDirectory)
37+
38+
release := &builder.Release{
39+
BuildOutputDirectory: buildOutputDirectory,
40+
ReleaseOutputDirectory: releaseOutputDirectory,
41+
}
42+
43+
if err := release.Run(ctx); err != nil {
44+
logger.Printf("Error releasing chaincode: %+v", err)
45+
46+
return 1
47+
}
48+
49+
return 0
50+
}

cmd/release/main.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,11 @@
33
package main
44

55
import (
6-
"context"
76
"os"
87

9-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/builder"
10-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/log"
11-
"github.com/hyperledger-labs/fabric-builder-k8s/internal/util"
12-
)
13-
14-
const (
15-
expectedArgsLength = 3
16-
buildOutputDirectoryArg = 1
17-
releaseOutputDirectoryArg = 2
8+
"github.com/hyperledger-labs/fabric-builder-k8s/cmd"
189
)
1910

2011
func main() {
21-
debug := util.GetOptionalEnv(util.DebugVariable, "false")
22-
ctx := log.NewCmdContext(context.Background(), debug == "true")
23-
logger := log.New(ctx)
24-
25-
if len(os.Args) != expectedArgsLength {
26-
logger.Println("Expected BUILD_OUTPUT_DIR and RELEASE_OUTPUT_DIR arguments")
27-
os.Exit(1)
28-
}
29-
30-
buildOutputDirectory := os.Args[buildOutputDirectoryArg]
31-
releaseOutputDirectory := os.Args[releaseOutputDirectoryArg]
32-
33-
logger.Debugf("Build output directory: %s", buildOutputDirectory)
34-
logger.Debugf("Release output directory: %s", releaseOutputDirectory)
35-
36-
release := &builder.Release{
37-
BuildOutputDirectory: buildOutputDirectory,
38-
ReleaseOutputDirectory: releaseOutputDirectory,
39-
}
40-
41-
if err := release.Run(ctx); err != nil {
42-
logger.Printf("Error releasing chaincode: %+v", err)
43-
os.Exit(1)
44-
}
12+
os.Exit(cmd.Release())
4513
}

0 commit comments

Comments
 (0)