Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add commander testing infrastucture #357

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Build
run: make build

- name: Run unit test
- name: Run tests
run: make test

shellcheck:
Expand Down Expand Up @@ -282,4 +282,4 @@ jobs:
--type slsaprovenance \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
--certificate-identity-regexp '^https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+$' \
$IMAGE@$DIGEST
$IMAGE@$DIGEST
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
22 changes: 21 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,9 @@ clean: ## Clean project files
@go clean
@rm -f ${BUILD_DIR}

test: ## Run tests
test: test-unit test-integration ## Run all tests

test-unit: ## Run unit tests
go test -race \
-coverpkg=./... \
-coverprofile=coverageunit.tmp.out \
Expand All @@ -84,6 +98,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"
Loading