Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 7570207

Browse files
author
Aleksandar Likic
committed
[FAB-5919] Refactor CI to run unit tests without docker
Change-Id: I0b18532a75a49184dd4840e3bc5c99999470275c Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
1 parent 6648c81 commit 7570207

File tree

11 files changed

+151
-116
lines changed

11 files changed

+151
-116
lines changed

Makefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,20 @@ restore-docker-file:
7070
&& sed -i.bak -e 's/$(DOCKER_TAG)/_TAG_/g' Dockerfile\
7171
&& rm -rf Dockerfile.bak
7272

73-
unit-test: clean depend populate edit-docker build-softhsm2-image restore-docker-file
74-
@cd ./test/fixtures && docker-compose -f docker-compose-unit.yaml up --abort-on-container-exit
75-
@test/scripts/check_status.sh "./test/fixtures/docker-compose-unit.yaml"
76-
73+
unit-test: checks depend populate
74+
@test/scripts/unit.sh
7775

7876
unit-tests: unit-test
7977

80-
integration-test: clean depend populate edit-docker build-softhsm2-image restore-docker-file
81-
@cd ./test/fixtures && docker-compose up --force-recreate --abort-on-container-exit
82-
@test/scripts/check_status.sh "./test/fixtures/docker-compose.yaml"
78+
integration-tests: clean depend populate edit-docker build-softhsm2-image restore-docker-file
79+
@cd ./test/fixtures && docker-compose -f docker-compose.yaml -f docker-compose-integration-test.yaml up --force-recreate --abort-on-container-exit
80+
@test/scripts/check_status.sh "-f ./test/fixtures/docker-compose.yaml -f ./test/fixtures/docker-compose-integration-test.yaml"
81+
82+
integration-tests-pkcs11: clean depend populate edit-docker build-softhsm2-image restore-docker-file
83+
@cd ./test/fixtures && docker-compose -f docker-compose.yaml -f docker-compose-pkcs11-test.yaml up --force-recreate --abort-on-container-exit
84+
@test/scripts/check_status.sh "-f ./test/fixtures/docker-compose.yaml -f ./test/fixtures/docker-compose-pkcs11-test.yaml"
8385

84-
integration-tests: integration-test
86+
integration-test: integration-tests integration-tests-pkcs11
8587

8688
mock-gen:
8789
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api/apitxn ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/apitxn/mocks/mockapitxn.gen.go
@@ -100,5 +102,4 @@ populate-clean:
100102
clean:
101103
rm -Rf /tmp/enroll_user /tmp/msp /tmp/keyvaluestore
102104
rm -f integration-report.xml report.xml
103-
cd test/fixtures && docker-compose down
104-
cd test/fixtures && docker-compose -f docker-compose-unit.yaml down
105+
cd test/fixtures && docker-compose -f docker-compose.yaml -f docker-compose-integration-test.yaml -f docker-compose-pkcs11-test.yaml down

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ repository.
3838
### Compatibility
3939

4040
This client SDK was last tested and found to be compatible with the following Hyperledger Fabric commit levels:
41-
- fabric: v1.0.1
42-
- fabric-ca: v1.0.1
41+
- fabric v1.0.1 & fabric-ca v1.0.1
42+
- fabric v1.0.0 & fabric-ca v1.0.0
4343

4444
### Running the test suite
4545

@@ -139,14 +139,14 @@ Alternatively you can build and run Fabric on your own box using the following c
139139
cd $GOPATH/src/github.com/hyperledger/
140140
git clone https://github.com/hyperledger/fabric
141141
cd $GOPATH/src/github.com/hyperledger/fabric/
142-
git checkout v1.0.0
142+
git checkout v1.0.1
143143
make docker
144144
145145
# Build fabric-ca:
146146
cd $GOPATH/src/github.com/hyperledger/
147147
git clone https://github.com/hyperledger/fabric-ca
148148
cd $GOPATH/src/github.com/hyperledger/fabric-ca/
149-
git checkout v1.0.0
149+
git checkout v1.0.1
150150
make docker
151151
152152
# Start fabric - latest-env.sh overrides the default docker tags in .env

pkg/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (c *Config) CSPConfig() *bccspFactory.FactoryOpts {
446446
Ephemeral: c.Ephemeral(),
447447
},
448448
}
449-
log.Debug("Initialized PKCS11 ")
449+
log.Debug("Initialized SW ")
450450
bccspFactory.InitFactories(opts)
451451
return opts
452452

@@ -471,6 +471,8 @@ func (c *Config) CSPConfig() *bccspFactory.FactoryOpts {
471471
bccspFactory.InitFactories(opts)
472472
return opts
473473

474+
default:
475+
panic(fmt.Sprintf("Unsupported BCCSP Provider: %s", c.SecurityProvider()))
476+
474477
}
475-
return nil
476478
}

pkg/config/config_test.go

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"time"
1616

1717
api "github.com/hyperledger/fabric-sdk-go/api/apiconfig"
18-
pkcsFactory "github.com/hyperledger/fabric/bccsp/factory"
19-
pkcs11 "github.com/hyperledger/fabric/bccsp/pkcs11"
2018
logging "github.com/op/go-logging"
2119
"github.com/spf13/viper"
2220
)
@@ -28,8 +26,7 @@ var bccspProviderType string
2826
var securityLevel = 256
2927

3028
const (
31-
providerTypeSW = "SW"
32-
providerTypePKCS11 = "PKCS11"
29+
providerTypeSW = "SW"
3330
)
3431

3532
var validRootCA = `-----BEGIN CERTIFICATE-----
@@ -277,19 +274,19 @@ func TestCSPConfig(t *testing.T) {
277274

278275
if cspconfig != nil && cspconfig.ProviderName == "SW" {
279276
if cspconfig.SwOpts.HashFamily != configImpl.SecurityAlgorithm() {
280-
t.Fatalf("In correct hashfamily found for cspconfig")
277+
t.Fatalf("Incorrect hashfamily found for cspconfig")
281278
}
282279

283280
if cspconfig.SwOpts.SecLevel != configImpl.SecurityLevel() {
284-
t.Fatalf("In correct security level found for cspconfig")
281+
t.Fatalf("Incorrect security level found for cspconfig")
285282
}
286283

287284
if cspconfig.SwOpts.Ephemeral {
288-
t.Fatalf("In correct Ephemeral found for cspconfig")
285+
t.Fatalf("Incorrect Ephemeral found for cspconfig")
289286
}
290287

291288
if cspconfig.SwOpts.FileKeystore.KeyStorePath != configImpl.KeyStorePath() {
292-
t.Fatalf("In correct keystore path found for cspconfig")
289+
t.Fatalf("Incorrect keystore path found for cspconfig")
293290
}
294291
}
295292
}
@@ -471,79 +468,6 @@ func TestNetworkConfig(t *testing.T) {
471468
}
472469
}
473470

474-
func TestPKCS11CSPConfigWithValidOptions(t *testing.T) {
475-
opts := configurePKCS11Options("SHA2", securityLevel)
476-
f := &pkcsFactory.PKCS11Factory{}
477-
//
478-
csp, err := f.Get(opts)
479-
if err != nil {
480-
t.Fatalf(err.Error())
481-
}
482-
if csp == nil {
483-
t.Fatalf("BCCSP PKCS11 was not configured")
484-
}
485-
fmt.Println("TestPKCS11CSPConfigWithValidOptions passed. BCCSP PKCS11 provider was configured\n", csp)
486-
487-
}
488-
489-
func TestPKCS11CSPConfigWithEmptyHashFamily(t *testing.T) {
490-
491-
opts := configurePKCS11Options("", securityLevel)
492-
493-
f := &pkcsFactory.PKCS11Factory{}
494-
fmt.Println(f.Name())
495-
_, err := f.Get(opts)
496-
if err == nil {
497-
t.Fatalf("Expected error 'Hash Family not supported'")
498-
}
499-
fmt.Println("TestPKCS11CSPConfigWithEmptyHashFamily passed. ")
500-
501-
}
502-
503-
func TestPKCS11CSPConfigWithIncorrectLevel(t *testing.T) {
504-
505-
opts := configurePKCS11Options("SHA2", 100)
506-
507-
f := &pkcsFactory.PKCS11Factory{}
508-
fmt.Println(f.Name())
509-
_, err := f.Get(opts)
510-
if err == nil {
511-
t.Fatalf("Expected error 'Failed initializing configuration'")
512-
}
513-
514-
}
515-
516-
func TestPKCS11CSPConfigWithEmptyProviderName(t *testing.T) {
517-
f := &pkcsFactory.PKCS11Factory{}
518-
if f.Name() != providerTypePKCS11 {
519-
t.Fatalf("Expected default name for PKCS11. Got %s", f.Name())
520-
}
521-
}
522-
523-
func configurePKCS11Options(hashFamily string, securityLevel int) *pkcsFactory.FactoryOpts {
524-
providerLib, softHSMPin, softHSMTokenLabel := pkcs11.FindPKCS11Lib()
525-
526-
pkks := pkcs11.FileKeystoreOpts{KeyStorePath: os.TempDir()}
527-
//PKCS11 options
528-
pkcsOpt := pkcs11.PKCS11Opts{
529-
SecLevel: securityLevel,
530-
HashFamily: hashFamily,
531-
FileKeystore: &pkks,
532-
Library: providerLib,
533-
Pin: softHSMPin,
534-
Label: softHSMTokenLabel,
535-
Ephemeral: false,
536-
}
537-
538-
opts := &pkcsFactory.FactoryOpts{
539-
ProviderName: providerTypePKCS11,
540-
Pkcs11Opts: &pkcsOpt,
541-
}
542-
pkcsFactory.InitFactories(opts)
543-
return opts
544-
545-
}
546-
547471
func TestMain(m *testing.M) {
548472
var err error
549473
configImpl, err = InitConfig("../../test/fixtures/config/config_test.yaml")

test/fixtures/config/config_test.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ client:
3333
security:
3434
enabled: true
3535
default:
36-
provider: "PKCS11"
36+
provider: "SW"
3737
hashAlgorithm: "SHA2"
3838
softVerify: true
3939
ephemeral: false
@@ -42,8 +42,6 @@ client:
4242
label: "ForFabric"
4343
library: "/usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so, /usr/lib/softhsm/libsofthsm2.so , /usr/lib/s390x-linux-gnu/softhsm/libsofthsm2.so, /usr/lib/powerpc64le-linux-gnu/softhsm/libsofthsm2.so, /usr/local/Cellar/softhsm/2.1.0/lib/softhsm/libsofthsm2.so"
4444

45-
46-
4745
# network provides a static definition of a Hyperledger Fabric network
4846
network:
4947
# list of ordering service nodes

test/fixtures/docker-compose-unit.yaml renamed to test/fixtures/docker-compose-integration-test.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
version: '2'
77

88
services:
9-
10-
fabric-sdk-testcase:
11-
container_name: fabric-sdk-softhsm2
9+
10+
fabric-sdk-integration-tests:
11+
container_name: fabric-sdk-integration-test
1212
image: softhsm2-image
1313
volumes:
1414
- ../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
15-
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/unit.sh
15+
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration.sh
16+
depends_on:
17+
- orderer.example.com
18+
- builder
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
version: '2'
7+
8+
services:
9+
10+
fabric-sdk-pkcs11-tests:
11+
container_name: fabric-sdk-pkcs11-test
12+
image: softhsm2-image
13+
environment:
14+
- FABRIC_SDK_CLIENT_BCCSP_SECURITY_DEFAULT_PROVIDER=PKCS11
15+
volumes:
16+
- ../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
17+
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration.sh
18+
depends_on:
19+
- orderer.example.com
20+
- builder

test/fixtures/docker-compose.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
2+
# Copyright SecureKey Technologies Inc. All Rights Reserved.
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
@@ -143,16 +143,6 @@ services:
143143
depends_on:
144144
- orderer.example.com
145145
- builder
146-
147-
fabric-sdk-int-tests:
148-
container_name: fabric-sdk-integration-softhsm2
149-
image: softhsm2-image
150-
volumes:
151-
- ../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
152-
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/integration-container.sh
153-
depends_on:
154-
- orderer.example.com
155-
- builder
156146

157147

158148
# builder is only here to create a dependency on the image (not used as part of compose)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package integration
8+
9+
import (
10+
"fmt"
11+
"os"
12+
"testing"
13+
14+
api "github.com/hyperledger/fabric-sdk-go/api/apiconfig"
15+
pkcsFactory "github.com/hyperledger/fabric/bccsp/factory"
16+
pkcs11 "github.com/hyperledger/fabric/bccsp/pkcs11"
17+
)
18+
19+
var configImpl api.Config
20+
var securityLevel = 256
21+
22+
const (
23+
providerTypePKCS11 = "PKCS11"
24+
)
25+
26+
func TestPKCS11CSPConfigWithValidOptions(t *testing.T) {
27+
opts := configurePKCS11Options("SHA2", securityLevel)
28+
f := &pkcsFactory.PKCS11Factory{}
29+
//
30+
csp, err := f.Get(opts)
31+
if err != nil {
32+
t.Fatalf(err.Error())
33+
}
34+
if csp == nil {
35+
t.Fatalf("BCCSP PKCS11 was not configured")
36+
}
37+
fmt.Println("TestPKCS11CSPConfigWithValidOptions passed. BCCSP PKCS11 provider was configured\n", csp)
38+
39+
}
40+
41+
func TestPKCS11CSPConfigWithEmptyHashFamily(t *testing.T) {
42+
43+
opts := configurePKCS11Options("", securityLevel)
44+
45+
f := &pkcsFactory.PKCS11Factory{}
46+
fmt.Println(f.Name())
47+
_, err := f.Get(opts)
48+
if err == nil {
49+
t.Fatalf("Expected error 'Hash Family not supported'")
50+
}
51+
fmt.Println("TestPKCS11CSPConfigWithEmptyHashFamily passed. ")
52+
53+
}
54+
55+
func TestPKCS11CSPConfigWithIncorrectLevel(t *testing.T) {
56+
57+
opts := configurePKCS11Options("SHA2", 100)
58+
59+
f := &pkcsFactory.PKCS11Factory{}
60+
fmt.Println(f.Name())
61+
_, err := f.Get(opts)
62+
if err == nil {
63+
t.Fatalf("Expected error 'Failed initializing configuration'")
64+
}
65+
66+
}
67+
68+
func TestPKCS11CSPConfigWithEmptyProviderName(t *testing.T) {
69+
f := &pkcsFactory.PKCS11Factory{}
70+
if f.Name() != providerTypePKCS11 {
71+
t.Fatalf("Expected default name for PKCS11. Got %s", f.Name())
72+
}
73+
}
74+
75+
func configurePKCS11Options(hashFamily string, securityLevel int) *pkcsFactory.FactoryOpts {
76+
providerLib, softHSMPin, softHSMTokenLabel := pkcs11.FindPKCS11Lib()
77+
78+
pkks := pkcs11.FileKeystoreOpts{KeyStorePath: os.TempDir()}
79+
//PKCS11 options
80+
pkcsOpt := pkcs11.PKCS11Opts{
81+
SecLevel: securityLevel,
82+
HashFamily: hashFamily,
83+
FileKeystore: &pkks,
84+
Library: providerLib,
85+
Pin: softHSMPin,
86+
Label: softHSMTokenLabel,
87+
Ephemeral: false,
88+
}
89+
90+
opts := &pkcsFactory.FactoryOpts{
91+
ProviderName: providerTypePKCS11,
92+
Pkcs11Opts: &pkcsOpt,
93+
}
94+
pkcsFactory.InitFactories(opts)
95+
return opts
96+
97+
}

test/scripts/check_status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
set -e
88
file_path=$1
99

10-
docker-compose --file=$file_path ps -q | xargs docker inspect -f '{{ .Name }},{{ .State.ExitCode }}' | \
10+
docker-compose $file_path ps -q | xargs docker inspect -f '{{ .Name }},{{ .State.ExitCode }}' | \
1111

1212
while read name ; do
1313
if echo "$name" | grep -q "softhsm2"

0 commit comments

Comments
 (0)