From 94e8b9cf86fcd71f83a21208940e28e421ca4ce9 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 1 Nov 2021 17:23:00 +0100 Subject: [PATCH] test: build example in jenkins Add command for generating coverage --- .gitignore | 5 +++++ Makefile | 21 ++++++++++++++++++++- ci/Jenkinsfile | 4 ++++ examples/basic2/main.go | 6 +++--- examples/filter2/main.go | 4 ++-- examples/peer_events/main.go | 6 +++--- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 8bb6d7b5..2c7a4b1a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,11 +8,16 @@ nodekey *.so *.dylib +# output binaries +main +go-waku + # Test binary, built with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out +coverage.html # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/Makefile b/Makefile index 9446b24b..24c88401 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all build lint test +.PHONY: all build lint test coverage build-example all: build @@ -24,9 +24,28 @@ test: generate: go generate ./waku/v2/protocol/pb/generate.go +coverage: + go test -count 1 -coverprofile=coverage.out ./... + go tool cover -html=coverage.out -o=coverage.html + # build a docker image for the fleet docker-image: DOCKER_IMAGE_TAG ?= latest docker-image: DOCKER_IMAGE_NAME ?= statusteam/go-waku:$(DOCKER_IMAGE_TAG) docker-image: docker build --tag $(DOCKER_IMAGE_NAME) \ --build-arg="GIT_COMMIT=$(shell git rev-parse HEAD)" . + +build-example-basic2: + go build examples/basic2/main.go + +build-example-chat-2: + # TODO: require UI + Chat which are gone + # go build examples/chat2/main.go + +build-example-filter2: + go build examples/filter2/main.go + +build-example-peer-events: + go build examples/peer_events/main.go + +build-example: build-example-basic2 build-example-chat-2 build-example-filter2 build-example-peer-events \ No newline at end of file diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile index 0f0026a4..4f080d41 100644 --- a/ci/Jenkinsfile +++ b/ci/Jenkinsfile @@ -28,6 +28,10 @@ pipeline { stage('Test') { steps { sh 'make test' } } + + stage('Build example') { + steps { sh 'make build-example' } + } } post { always { cleanWs() } diff --git a/examples/basic2/main.go b/examples/basic2/main.go index 734c7567..68525b97 100644 --- a/examples/basic2/main.go +++ b/examples/basic2/main.go @@ -40,7 +40,7 @@ func main() { wakuNode, err := node.New(ctx, node.WithPrivateKey(prvKey), - node.WithHostAddress([]net.Addr{hostAddr}), + node.WithHostAddress([]*net.TCPAddr{hostAddr}), node.WithWakuRelay(), ) if err != nil { @@ -93,7 +93,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { Timestamp: timestamp, } - _, err = wakuNode.Publish(ctx, msg, nil) + _, err = wakuNode.Relay().Publish(ctx, msg, nil) if err != nil { log.Error("Error sending a message: ", err) } @@ -107,7 +107,7 @@ func writeLoop(ctx context.Context, wakuNode *node.WakuNode) { } func readLoop(ctx context.Context, wakuNode *node.WakuNode) { - sub, err := wakuNode.Subscribe(ctx, nil) + sub, err := wakuNode.Relay().Subscribe(ctx, nil) if err != nil { log.Error("Could not subscribe: ", err) return diff --git a/examples/filter2/main.go b/examples/filter2/main.go index 8ac23c96..8094603d 100644 --- a/examples/filter2/main.go +++ b/examples/filter2/main.go @@ -146,7 +146,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { Timestamp: timestamp, } - _, err := wakuNode.Publish(ctx, msg, nil) + _, err := wakuNode.Relay().Publish(ctx, msg, nil) if err != nil { log.Error("Error sending a message: ", err) } @@ -160,7 +160,7 @@ func writeLoop(ctx context.Context, wakuNode *node.WakuNode) { } func readLoop(ctx context.Context, wakuNode *node.WakuNode) { - sub, err := wakuNode.Subscribe(ctx, &pubSubTopic) + sub, err := wakuNode.Relay().Subscribe(ctx, &pubSubTopic) if err != nil { log.Error("Could not subscribe: ", err) return diff --git a/examples/peer_events/main.go b/examples/peer_events/main.go index b28e5d3c..e21e6598 100644 --- a/examples/peer_events/main.go +++ b/examples/peer_events/main.go @@ -62,7 +62,7 @@ func main() { log.Info("### create relayNode1") relayNode1, err := node.New(ctx, node.WithPrivateKey(addrsAndKeys[0].key), - node.WithHostAddress([]net.Addr{addrsAndKeys[0].addr}), + node.WithHostAddress([]*net.TCPAddr{addrsAndKeys[0].addr}), node.WithWakuRelay(), //node.WithConnStatusChan(connStatusChan), node.WithWakuStore(true, false), @@ -198,7 +198,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { Timestamp: timestamp, } - _, err = wakuNode.Publish(ctx, msg, nil) + _, err = wakuNode.Relay().Publish(ctx, msg, nil) if err != nil { log.Error("Error sending a message: ", err) } @@ -213,7 +213,7 @@ func writeLoop(ctx context.Context, wakuNode *node.WakuNode) { } func readLoop(ctx context.Context, wakuNode *node.WakuNode) { - sub, err := wakuNode.Subscribe(ctx, &pubSubTopic) + sub, err := wakuNode.Relay().Subscribe(ctx, &pubSubTopic) if err != nil { log.Error("Could not subscribe: ", err) return