Skip to content

Commit

Permalink
test: add commander testing infrastucture
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jun 27, 2024
1 parent 41629a5 commit f95c052
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
coverage/
*.out

# Dependency directories (remove the comment below to include it)
Expand Down
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ $(GO_BIN)/mockgen:
@echo "==> Installing mockgen within ${GO_BIN}"
@go install go.uber.org/mock/mockgen@latest

$(GO_BIN)/commander:
@echo "==> Installing commander within ${GO_BIN}"
@go install github.com/commander-cli/commander/v2/cmd/commander@latest

$(MOCK_SRC_DIR):
@echo "==> Cloning OpenFGA Go SDK within ${MOCK_SRC_DIR}"
@git clone https://github.com/openfga/go-sdk ${MOCK_SRC_DIR}
Expand All @@ -60,10 +64,18 @@ help: ## Show this help
build: ## Build the CLI binary
@echo "==> Building binary within ${BUILD_DIR}/${BINARY_NAME}"
@go build -v -ldflags "$(GO_LINKER_FLAGS)" -o "${BUILD_DIR}/${BINARY_NAME}" "$(CURDIR)/cmd/fga/main.go"

build-with-cover: ## Build the CLI binary for the native platform with coverage support
@echo "Building the cli binary"
@go build -cover -ldflags "$(GO_LINKER_FLAGS)" -o "${BUILD_DIR}/${BINARY_NAME}" "$(CURDIR)/cmd/fga/main.go"

install: ## Install the CLI binary
@$(MAKE) build BUILD_DIR="$(GO_BIN)"

install-with-cover: ## Install the CLI binary for the native platform with coverage support
@echo "Installing the CLI binary with coverage support"
@$(MAKE) build-with-cover BUILD_DIR="$(GO_BIN)"

run: $(GO_BIN)/CompileDaemon ## Watch for changes and recompile the CLI binary
@echo "==> Watching for changes"
@CompileDaemon -build='make install' -command='fga --version'
Expand All @@ -73,7 +85,7 @@ clean: ## Clean project files
@go clean
@rm -f ${BUILD_DIR}

test: ## Run tests
test: ## Run unit tests
go test -race \
-coverpkg=./... \
-coverprofile=coverageunit.tmp.out \
Expand All @@ -84,6 +96,12 @@ test: ## Run tests
@cat coverageunit.tmp.out | grep -v "mocks" > coverageunit.out
@rm coverageunit.tmp.out

test-integration: install-with-cover $(GO_BIN)/fga $(GO_BIN)/commander ## Run integration tests
@echo "==> Running integration tests"
@mkdir -p "coverage"
@PATH=$(GO_BIN):$$PATH GOCOVERDIR=coverage bash ./tests/scripts/run-test-suites.sh
@go tool covdata textfmt -i "coverage" -o "coverage-integration-tests.out"

lint: $(GO_BIN)/golangci-lint ## Lint Go source files
@echo "==> Linting Go source files"
@golangci-lint run -v --fix -c .golangci.yaml ./...
Expand Down
14 changes: 14 additions & 0 deletions tests/scripts/run-test-suites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /bin/bash -v

docker run -p 8080:8080 -p 8081:8081 -p 3000:3000 -d --name openfga-cli-tests openfga/openfga run

set +e

commander test --dir ./tests

exit_code=$?

docker stop openfga-cli-tests
docker rm openfga-cli-tests

exit $exit_code
10 changes: 10 additions & 0 deletions tests/store-test-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config:
inherit-env: true

tests:
001 - it successfully uses the store command to create a new store:
command: fga store create --name "FGA Demo Store"
exit-code: 0
stdout:
json:
store.name: "FGA Demo Store"

0 comments on commit f95c052

Please sign in to comment.