From cf86376ce3acd0e9c6a167a76a5afda9ebf0225f Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Tue, 2 Jul 2024 19:33:39 -0400 Subject: [PATCH] enhance: add simple integration test Signed-off-by: Grant Linville --- .github/workflows/integration.yaml | 40 ++++++++++++++++++++++++++++++ Makefile | 6 ++++- integration/cred_test.go | 13 ++++++++++ integration/helpers.go | 16 ++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/integration.yaml create mode 100644 integration/cred_test.go create mode 100644 integration/helpers.go diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml new file mode 100644 index 00000000..e0b78be2 --- /dev/null +++ b/.github/workflows/integration.yaml @@ -0,0 +1,40 @@ +name: integration + +on: + push: + branches: + - main + paths-ignore: + - docs/** + - tools/** + - README.md + pull_request: + branches: + - main + paths-ignore: + - docs/** + - tools/** + - README.md + +jobs: + integration: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04, windows-latest] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: actions/setup-go@v5 + with: + cache: false + go-version: "1.22" + - name: Build + if: matrix.os == 'ubuntu-22.04' + run: make build + - name: build-windows + if: matrix.os == 'windows-latest' + run: make build-exe + - name: Run Integration Tests + run: make integration \ No newline at end of file diff --git a/Makefile b/Makefile index 0fed6344..e0d93a1d 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,11 @@ tidy: go mod tidy test: - go test -v ./... + go test -v ./pkg/... + +.PHONY: integration +integration: + go test -v ./integration/... smoke: build smoke: diff --git a/integration/cred_test.go b/integration/cred_test.go new file mode 100644 index 00000000..b92ccd55 --- /dev/null +++ b/integration/cred_test.go @@ -0,0 +1,13 @@ +package integration + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGPTScriptCredential(t *testing.T) { + out, err := GPTScriptExec("cred") + require.NoError(t, err) + require.Contains(t, out, "CREDENTIAL") +} diff --git a/integration/helpers.go b/integration/helpers.go new file mode 100644 index 00000000..8af581c3 --- /dev/null +++ b/integration/helpers.go @@ -0,0 +1,16 @@ +package integration + +import ( + "os/exec" + "runtime" +) + +func GPTScriptExec(args ...string) (string, error) { + cmd := exec.Command("../bin/gptscript", args...) + if runtime.GOOS == "windows" { + cmd = exec.Command("..\\bin\\gptscript.exe", args...) + } + + out, err := cmd.CombinedOutput() + return string(out), err +}