-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: s8sg <swarvanusg@gmail.com>
- Loading branch information
Showing
6 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
INTEGRATION_TEST_PATH?=./integration-test | ||
EXAMPLES_PATH?=./samples | ||
|
||
.PHONY: build | ||
all: coverage | ||
all: build coverage | ||
|
||
build: | __go-pkg-list | ||
@go build --ldflags "-s -w" -a -installsuffix cgo ${GO_PKG_LIST} | ||
|
||
## coverage: Generate global code coverage report | ||
.PHONY: coverage | ||
coverage: | __go-pkg-list | ||
@go test -gcflags=-l -v ${GO_PKG_LIST} -coverprofile /tmp/pls_cp.out || true | ||
coverage: | __go-pkg-list unit integration | ||
@go tool cover -html=/tmp/pls_cp.out -o /tmp/coverage.html | ||
@echo "You can find coverage report at /tmp/coverage.html" | ||
|
||
## coverage: Generate global code coverage report | ||
.PHONY: unit | ||
test.unit: | __go-pkg-list | ||
@go test -tags=unit -gcflags=-l -v ${GO_PKG_LIST} -coverprofile /tmp/pls_cp.out | ||
|
||
|
||
## Run integration test | ||
.PHONY: integration | ||
test.integration: | ||
go test -tags=integration $(INTEGRATION_TEST_PATH) $(EXAMPLES_PATH) -count=1 -v -coverprofile /tmp/pls_cp.out | ||
|
||
## docker.start: Starts docker compose | ||
docker.start: | ||
@docker-compose up -d | ||
|
||
## docker.start: Starts docker compose | ||
docker.stop: | ||
@docker-compose down | ||
|
||
__go-pkg-list: | ||
ifeq ($(origin GO_PKG_LIST), undefined) | ||
$(eval GO_PKG_LIST ?= $(shell go list ./... | grep -v /doc/ | grep -v /template/ | grep -v /vendor/)) | ||
endif | ||
$(eval GO_PKG_LIST ?= $(shell go list ./... | grep -v /doc/ | grep -v /template/ | grep -v /vendor/ | grep -v samples | grep -v integration-test)) | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"net/http" | ||
"github.com/stretchr/testify/assert" | ||
"time" | ||
"log" | ||
) | ||
|
||
|
||
|
||
func runExamplesServer() { | ||
go func() { | ||
fs := GetFlowService() | ||
log.Fatalf(fs.Start().Error()) | ||
}() | ||
} | ||
|
||
func waitForServer() { | ||
backoff := 50 * time.Millisecond | ||
log.Printf("waiting for server to start") | ||
for i := 0; i < 10; i++ { | ||
// TODO: Add health check endpoint | ||
_, err := http.Get("http://localhost:8080/flow/single") | ||
if err != nil { | ||
time.Sleep(backoff) | ||
continue | ||
} | ||
log.Printf("server started") | ||
return | ||
} | ||
log.Fatalf("Server on localhost:8080 not up after 10 attempts") | ||
} | ||
|
||
|
||
func Test_single_flow_execution(t *testing.T) { | ||
runExamplesServer() | ||
waitForServer() | ||
|
||
t.Run("it should return 200 when executing single flow", func(t *testing.T) { | ||
resp, err := http.Get("http://localhost:8080/flow/single") | ||
|
||
if err != nil { | ||
t.Fatalf("Expected no error, got %v", err) | ||
} | ||
|
||
assert.Equal(t, 200, resp.StatusCode) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters