Skip to content

Commit d209485

Browse files
christo4ferristong  li
authored and
tong li
committed
FAB-4161 Run only patch sepecific unit test cases
Currently at CI, entire unit test cases were run which results significant long run jobs. This change will make sure only the changed packages unit test cases will be run at CI. Merge patch set CI jobs will be still run the full unit test cases. Use go test -cover as opposed to gocov for improved performance Use git diff --name-only to find uncommitted changes Add 'verify' target to Makefile Add a test go source file to test the build generate html coverage report on merge job Also covers FAB-4192 Makefile improvements Refine the list of PROJECT_FILES omitting things that don't affect the build targets using that dependency Remove unnecessary dependencies Have check_spelling.sh and check_license.sh only work on changed files. include last commit content for CI Also addressed some spelling errors that slipped in. address binh's comment re generated files Signed-off-by: tong li <[email protected]> Signed-off-by: Christopher Ferris <[email protected]> Signed-off-by: Rameshthoomu <[email protected]> Change-Id: Ib2759219ced54d15fe7c9e5113bd9b1259ea68c5
1 parent 38d3879 commit d209485

File tree

12 files changed

+114
-113
lines changed

12 files changed

+114
-113
lines changed

Makefile

100644100755
+23-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
# Copyright IBM Corp All Rights Reserved.
22
# Copyright London Stock Exchange Group All Rights Reserved.
33
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
4+
# SPDX-License-Identifier: Apache-2.0
155
#
166
# -------------------------------------------------------------
177
# This makefile defines the following targets
188
#
199
# - all (default) - builds all targets and runs all tests/checks
2010
# - checks - runs all tests/checks
11+
# - desk-check - runs linters and verify to test changed packages
2112
# - configtxgen - builds a native configtxgen binary
2213
# - cryptogen - builds a native cryptogen binary
2314
# - peer - builds a native fabric peer binary
2415
# - orderer - builds a native fabric orderer binary
2516
# - release - builds release packages for the host platform
2617
# - release-all - builds release packages for all target platforms
2718
# - unit-test - runs the go-test based unit tests
19+
# - verify - runs unit tests for only the changed package tree
2820
# - test-cmd - generates a "go test" string suitable for manual customization
2921
# - behave - runs the behave test
3022
# - behave-deps - ensures pre-requisites are available for running behave manually
@@ -81,7 +73,11 @@ K := $(foreach exec,$(EXECUTABLES),\
8173
GOSHIM_DEPS = $(shell ./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim)
8274
JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
8375
PROTOS = $(shell git ls-files *.proto | grep -v vendor)
84-
PROJECT_FILES = $(shell git ls-files)
76+
# No sense rebuilding when non production code is changed
77+
PROJECT_FILES = $(shell git ls-files | grep -v ^test | grep -v ^unit-test | \
78+
grep -v ^bddtests | grep -v ^docs | grep -v _test.go$ | grep -v .md$ | \
79+
grep -v ^.git | grep -v ^examples | grep -v ^devenv | grep -v .png$ | \
80+
grep -v ^LICENSE )
8581
IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka couchdb tools
8682
RELEASE_PLATFORMS = windows-amd64 darwin-amd64 linux-amd64 linux-ppc64le linux-s390x
8783
RELEASE_PKGS = configtxgen cryptogen configtxlator
@@ -98,19 +94,24 @@ include docker-env.mk
9894

9995
all: native docker checks
10096

101-
checks: linter license spelling unit-test behave
97+
checks: license spelling linter unit-test behave
98+
99+
desk-check: license spelling linter verify behave
102100

103-
spelling: buildenv
101+
.PHONY: spelling
102+
spelling:
104103
@scripts/check_spelling.sh
105104

106-
license: buildenv
105+
.PHONY: license
106+
license:
107107
@scripts/check_license.sh
108108

109109
.PHONY: gotools
110110
gotools:
111111
mkdir -p build/bin
112112
cd gotools && $(MAKE) install BINDIR=$(GOPATH)/bin
113113

114+
.PHONY: gotools-clean
114115
gotools-clean:
115116
cd gotools && $(MAKE) clean
116117

@@ -145,11 +146,18 @@ testenv: build/image/testenv/$(DUMMY)
145146

146147
couchdb: build/image/couchdb/$(DUMMY)
147148

149+
kafka: build/image/kafka/$(DUMMY)
150+
151+
zookeeper: build/image/zookeeper/$(DUMMY)
152+
148153
unit-test: unit-test-clean peer-docker testenv couchdb
149154
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
150155

151156
unit-tests: unit-test
152157

158+
verify: unit-test-clean peer-docker testenv couchdb
159+
cd unit-test && JOB_TYPE=VERIFY docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
160+
153161
# Generates a string to the terminal suitable for manual augmentation / re-issue, useful for running tests by hand
154162
test-cmd:
155163
@echo "go test -ldflags \"$(GO_LDFLAGS)\""

core/endorser/endorser.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
22
Copyright IBM Corp. 2016 All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package endorser

gossip/discovery/discovery_test.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
22
Copyright IBM Corp. 2016 All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package discovery
@@ -975,7 +965,7 @@ func TestMsgStoreExpirationWithMembershipMessages(t *testing.T) {
975965

976966
// Checking is Alive was processed
977967
for i := 0; i < peersNum; i++ {
978-
checkAliveMsgExist(instances, aliveMsgs, i, "[Step 1 - proccessing aliveMsg]")
968+
checkAliveMsgExist(instances, aliveMsgs, i, "[Step 1 - processing aliveMsg]")
979969
}
980970

981971
// Creating MembershipResponse while all instances have full membership

gotools/Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ OBJDIR ?= build
1818
TMP_GOPATH=$(OBJDIR)/gopath
1919
GOBIN=$(abspath $(TMP_GOPATH)/bin)
2020

21-
GOTOOLS = golint govendor goimports protoc-gen-go ginkgo gocov gocov-xml misspell
21+
GOTOOLS = golint govendor goimports protoc-gen-go ginkgo gocov gocov-html misspell
2222
GOTOOLS_BIN = $(patsubst %,$(GOBIN)/%, $(GOTOOLS))
2323

2424
# go tool->path mapping
@@ -27,9 +27,8 @@ go.fqp.golint := github.com/golang/lint/golint
2727
go.fqp.goimports := golang.org/x/tools/cmd/goimports
2828
go.fqp.ginkgo := github.com/onsi/ginkgo/ginkgo
2929
go.fqp.gocov := github.com/axw/gocov/...
30-
go.fqp.gocov-xml := github.com/AlekSi/gocov-xml
3130
go.fqp.misspell := github.com/client9/misspell/cmd/misspell
32-
31+
go.fqp.gocov-html:= github.com/matm/gocov-html
3332
all: $(GOTOOLS_BIN)
3433

3534
install: $(GOTOOLS_BIN)

protos/utils/txutils_test.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
/*
22
Copyright IBM Corp. 2017 All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
4+
SPDX-License-Identifier: Apache-2.0
155
*/
166

177
package utils_test
@@ -218,7 +208,7 @@ func TestCreateSignedTx(t *testing.T) {
218208

219209
//
220210
//
221-
// addtional failure cases
211+
// additional failure cases
222212
prop = &pb.Proposal{}
223213
responses = []*pb.ProposalResponse{}
224214
// no proposal responses

scripts/check_license.sh

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
# SPDX-License-Identifier: Apache-2.0
66
#
77

8+
CHECK=$(git diff --name-only HEAD * | grep -v .png$ | grep -v .rst$ | grep -v .git \
9+
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | sort -u)
810

9-
echo "Checking Go files for license headers ..."
10-
missing=`find . -name "*.go" | grep -v build/ | grep -v vendor/ | grep -v ".pb.go" | grep -v "examples/chaincode/go/utxo/consensus/consensus.go" | xargs grep -l -L "Apache License"`
11+
if [[ -z "$CHECK" ]]; then
12+
CHECK=$(git diff-tree --no-commit-id --name-only -r $(git log -2 \
13+
--pretty=format:"%h") | grep -v .png$ | grep -v .rst$ | grep -v .git \
14+
| grep -v .md$ | grep -v ^vendor/ | grep -v ^build/ | grep -v .pb.go$ | sort -u)
15+
fi
16+
17+
echo "Checking committed files for SPDX-License-Identifier headers ..."
18+
missing=`echo $CHECK | xargs grep -L "SPDX-License-Identifier"`
1119
if [ -z "$missing" ]; then
12-
echo "All go files have license headers"
20+
echo "All files have SPDX-License-Identifier headers"
1321
exit 0
1422
fi
15-
echo "The following files are missing license headers:"
23+
echo "The following files are missing SPDX-License-Identifier headers:"
1624
echo "$missing"
25+
echo
26+
echo "Please replace the Apache license header comment text with:"
27+
echo "SPDX-License-Identifier: Apache-2.0"
1728
exit 1

scripts/check_spelling.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
# SPDX-License-Identifier: Apache-2.0
66
#
77

8+
CHECK=$(git diff --name-only HEAD * | grep -v .png$ | grep -v .git \
9+
| grep -v ^vendor/ | grep -v ^build/ | sort -u)
810

9-
echo "Checking Go files for spelling errors ..."
10-
errs=`find . -name "*.go" | grep -v vendor/ | grep -v build/ | grep -v ".pb.go" | xargs misspell`
11+
if [[ -z "$CHECK" ]]; then
12+
CHECK=$(git diff-tree --no-commit-id --name-only -r $(git log -2 \
13+
--pretty=format:"%h") | grep -v .png$ | grep -v .git \
14+
| grep -v ^vendor/ | grep -v ^build/ | sort -u)
15+
fi
16+
17+
echo "Checking changed go files for spelling errors ..."
18+
errs=`echo $CHECK | xargs misspell -source=text`
1119
if [ -z "$errs" ]; then
1220
echo "spell checker passed"
1321
exit 0

test/chaincodes/AuctionApp/art.go

+18-28
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
/******************************************************************
1+
/*
22
Copyright IT People Corp. 2017 All Rights Reserved.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
4+
SPDX-License-Identifier: Apache-2.0
75
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
16-
******************************************************************/
6+
*/
177

188
///////////////////////////////////////////////////////////////////////
199
// Author : IT People - Mohan Venkataraman - Auction API for v1.0
@@ -394,7 +384,7 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, function strin
394384

395385
if len(args) < 1 {
396386
fmt.Println("Query() : Include at least 1 arguments Key ")
397-
return shim.Error("Query() : Expecting Transation type and Key value for query")
387+
return shim.Error("Query() : Expecting Transaction type and Key value for query")
398388
}
399389

400390
QueryRequest := QueryFunction(function)
@@ -457,7 +447,7 @@ func GetUser(stub shim.ChaincodeStubInterface, function string, args []string) p
457447
return shim.Error(jsonResp)
458448
}
459449

460-
fmt.Println("GetUser() : Response : Successfull -")
450+
fmt.Println("GetUser() : Response : Successful -")
461451
return shim.Success(Avalbytes)
462452
}
463453

@@ -491,7 +481,7 @@ func GetItem(stub shim.ChaincodeStubInterface, function string, args []string) p
491481
itemObj.ItemImage = []byte{}
492482
Avalbytes, _ = ARtoJSON(itemObj)
493483

494-
fmt.Println("GetItem() : Response : Successfull ")
484+
fmt.Println("GetItem() : Response : Successful ")
495485
return shim.Success(Avalbytes)
496486
}
497487

@@ -546,7 +536,7 @@ func ValidateItemOwnership(stub shim.ChaincodeStubInterface, function string, ar
546536
return shim.Error(jsonResp)
547537
}
548538

549-
fmt.Print("ValidateItemOwnership() : Response : Successfull - \n")
539+
fmt.Print("ValidateItemOwnership() : Response : Successful - \n")
550540
return shim.Success(Avalbytes)
551541
}
552542

@@ -575,7 +565,7 @@ func GetAuctionRequest(stub shim.ChaincodeStubInterface, function string, args [
575565
return shim.Error(jsonResp)
576566
}
577567

578-
fmt.Println("GetAuctionRequest() : Response : Successfull - \n")
568+
fmt.Println("GetAuctionRequest() : Response : Successful - \n")
579569
return shim.Success(Avalbytes)
580570
}
581571

@@ -611,7 +601,7 @@ func GetBid(stub shim.ChaincodeStubInterface, function string, args []string) pb
611601
return shim.Error(jsonResp)
612602
}
613603

614-
fmt.Println("GetBid() : Response : Successfull -")
604+
fmt.Println("GetBid() : Response : Successful -")
615605
return shim.Success(Avalbytes)
616606
}
617607

@@ -639,7 +629,7 @@ func GetTransaction(stub shim.ChaincodeStubInterface, function string, args []st
639629
return shim.Error(jsonResp)
640630
}
641631

642-
fmt.Println("GetTransaction() : Response : Successfull")
632+
fmt.Println("GetTransaction() : Response : Successful")
643633
return shim.Success(Avalbytes)
644634
}
645635

@@ -649,7 +639,7 @@ func GetTransaction(stub shim.ChaincodeStubInterface, function string, args []st
649639
// There are different types of users - Traders (TRD), Auction Houses (AH)
650640
// Shippers (SHP), Insurance Companies (INS), Banks (BNK)
651641
// While this version of the chain code does not enforce strict validation
652-
// the business process recomends validating each persona for the service
642+
// the business process recommends validating each persona for the service
653643
// they provide or their participation on the auction blockchain, future enhancements will do that
654644
// ./peer chaincode invoke -l golang -n mycc -c '{"Function": "PostUser", "Args":["100", "USER", "Ashley Hart", "TRD", "Morrisville Parkway, #216, Morrisville, NC 27560", "9198063535", "[email protected]", "SUNTRUST", "00017102345", "0234678"]}'
655645
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -934,7 +924,7 @@ func TransferItem(stub shim.ChaincodeStubInterface, function string, args []stri
934924
myItem.AES_Key, _ = GenAESKey()
935925
myItem.ItemImage = Encrypt(myItem.AES_Key, image)
936926

937-
// Update the owner to the new owner transfered to
927+
// Update the owner to the new owner transferred to
938928
myItem.CurrentOwnerID = args[3]
939929

940930
ar, err = ARtoJSON(myItem)
@@ -1193,7 +1183,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
11931183

11941184
buyer := response.Payload
11951185

1196-
fmt.Println("PostTransaction(): Validated Buyer information successfully ", buyer, ar.UserId)
1186+
fmt.Println("PostTransaction(): Validated Buyer information Successfully ", buyer, ar.UserId)
11971187

11981188
// Validate Item record
11991189
response = ValidateItemSubmission(stub, ar.ItemID)
@@ -1203,7 +1193,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12031193
}
12041194

12051195
lastUpdatedItemOBCObject := response.Payload
1206-
fmt.Println("PostTransaction() : Validated Item Object in Blockchain successfully", ar.ItemID)
1196+
fmt.Println("PostTransaction() : Validated Item Object in Blockchain Successfully", ar.ItemID)
12071197

12081198
// Update Item Object with new Owner Key
12091199
response = UpdateItemObject(stub, lastUpdatedItemOBCObject, ar.HammerPrice, ar.UserId)
@@ -1216,7 +1206,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12161206
fmt.Println("PostTransaction() : New encryption Key is ", newKey)
12171207
}
12181208

1219-
fmt.Println("PostTransaction() : Updated Item Master Object in Blockchain successfully", ar.ItemID)
1209+
fmt.Println("PostTransaction() : Updated Item Master Object in Blockchain Successfully", ar.ItemID)
12201210

12211211
// Post an Item Log
12221212
itemObject, err := JSONtoAR(lastUpdatedItemOBCObject)
@@ -1235,7 +1225,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12351225
return shim.Error(err.Error())
12361226
}
12371227

1238-
fmt.Println("PostTransaction() : Inserted item log record successfully", ar.ItemID)
1228+
fmt.Println("PostTransaction() : Inserted item log record Successfully", ar.ItemID)
12391229

12401230
// Convert Transaction Object to JSON
12411231
buff, err := TrantoJSON(ar) //
@@ -1252,7 +1242,7 @@ func PostTransaction(stub shim.ChaincodeStubInterface, function string, args []s
12521242
return shim.Error(err.Error())
12531243
}
12541244

1255-
fmt.Println("PostTransaction() : Posted Transaction Record successfully\n")
1245+
fmt.Println("PostTransaction() : Posted Transaction Record Successfully\n")
12561246

12571247
// Returns New Key. To get Transaction Details, run GetTransaction
12581248

@@ -2545,7 +2535,7 @@ func ProcessQueryResult(stub shim.ChaincodeStubInterface, Avalbytes []byte, args
25452535
fmt.Println("ProcessRequestType() : Image decrytion failed ")
25462536
return err
25472537
}
2548-
fmt.Println("ProcessRequestType() : Image conversion from byte[] to file successfull ")
2538+
fmt.Println("ProcessRequestType() : Image conversion from byte[] to file Successful ")
25492539
err = ByteArrayToImage(image, "copy."+ar.ItemPicFN)
25502540
if err != nil {
25512541

0 commit comments

Comments
 (0)