Skip to content

Commit b47e01a

Browse files
authored
Add acceptance test job and --to and --from tests (#136)
1 parent 3981f0d commit b47e01a

File tree

11 files changed

+413
-117
lines changed

11 files changed

+413
-117
lines changed

.github/workflows/11-test-acceptance.yaml

Lines changed: 84 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
repository: turbot/pipe-fittings
3131
path: pipe-fittings
32-
ref: tp
32+
ref: tp-pragma
3333

3434
- name: Checkout Tailpipe plugin SDK repository
3535
uses: actions/checkout@v4
@@ -82,121 +82,90 @@ jobs:
8282
if-no-files-found: error
8383

8484
# TODO - Update the acceptance test job with the correct test suite
85-
# acceptance_test:
86-
# name: Test
87-
# needs: goreleaser
88-
# strategy:
89-
# fail-fast: false
90-
# matrix:
91-
# platform: [ubuntu-latest]
92-
# test_block:
93-
# - "check"
94-
# - "resource_show_outputs"
95-
# - "dashboard"
96-
# - "backend"
97-
# - "mod"
98-
# - "mod_install"
99-
# - "sp_files"
100-
# - "var_resolution"
101-
# - "params_and_args"
102-
# - "snapshot"
103-
# - "dashboard_parsing_validation"
104-
# - "database_precedence"
105-
# runs-on: ${{ matrix.platform }}
106-
# steps:
107-
# - name: Checkout
108-
# uses: actions/checkout@v4
109-
# with:
110-
# submodules: true
111-
# path: powerpipe
112-
# ref: ${{ github.event.ref }}
113-
114-
# - uses: actions/setup-go@v5
115-
# with:
116-
# go-version: 1.22
117-
# cache: false
118-
119-
# - name: Prepare for downloads
120-
# id: prepare-for-downloads
121-
# run: |
122-
# mkdir ~/artifacts
85+
acceptance_test:
86+
name: Test
87+
needs: goreleaser
88+
strategy:
89+
fail-fast: false
90+
matrix:
91+
platform: [ubuntu-latest]
92+
test_block:
93+
- "all_column_types"
94+
- "from_and_to"
95+
runs-on: ${{ matrix.platform }}
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v4
99+
with:
100+
submodules: true
101+
path: tailpipe
102+
ref: ${{ github.event.ref }}
103+
104+
- uses: actions/setup-go@v5
105+
with:
106+
go-version: 1.22
107+
cache: false
108+
109+
- name: Prepare for downloads
110+
id: prepare-for-downloads
111+
run: |
112+
mkdir ~/artifacts
123113
124-
# - name: Download Linux Build Artifacts
125-
# uses: actions/download-artifact@v3
126-
# if: ${{ matrix.platform == 'ubuntu-latest' }}
127-
# with:
128-
# name: build-artifact-linux
129-
# path: ~/artifacts
130-
131-
# - name: Download Darwin Build Artifacts
132-
# uses: actions/download-artifact@v3
133-
# if: ${{ matrix.platform == 'macos-latest' }}
134-
# with:
135-
# name: build-artifact-darwin
136-
# path: ~/artifacts
137-
138-
# - name: Extract Darwin Artifacts and Install Binary
139-
# if: ${{ matrix.platform == 'macos-latest' }}
140-
# run: |
141-
# mkdir ~/build
142-
# tar -xf ~/artifacts/darwin.tar.gz -C ~/build
143-
144-
# - name: Extract Ubuntu Artifacts and Install Binary
145-
# if: ${{ matrix.platform == 'ubuntu-latest' }}
146-
# run: |
147-
# mkdir ~/build
148-
# tar -xf ~/artifacts/linux.tar.gz -C ~/build
149-
150-
# - name: Install Steampipe(Darwin)
151-
# if: ${{ matrix.platform == 'macos-latest' }}
152-
# run: |
153-
# brew install turbot/tap/steampipe
154-
# steampipe -v
155-
156-
# - name: Install Steampipe(Linux)
157-
# if: ${{ matrix.platform == 'ubuntu-latest' }}
158-
# run: |
159-
# sudo /bin/sh -c "$(curl -fsSL https://steampipe.io/install/steampipe.sh)"
160-
# steampipe -v
114+
- name: Download Linux Build Artifacts
115+
uses: actions/download-artifact@v3
116+
if: ${{ matrix.platform == 'ubuntu-latest' }}
117+
with:
118+
name: build-artifact-linux
119+
path: ~/artifacts
120+
121+
- name: Extract Ubuntu Artifacts and Install Binary
122+
if: ${{ matrix.platform == 'ubuntu-latest' }}
123+
run: |
124+
mkdir ~/build
125+
tar -xf ~/artifacts/linux.tar.gz -C ~/build
161126
162-
# - name: Set PATH
163-
# run: |
164-
# echo "PATH=$PATH:$HOME/build:$GTIHUB_WORKSPACE/powerpipe/tests/acceptance/lib/bats-core/libexec" >> $GITHUB_ENV
165-
166-
# - name: Go install jd
167-
# run: |
168-
# go install github.com/josephburnett/jd@latest
169-
170-
# - name: Start steamipipe service
171-
# run: |
172-
# steampipe service start
173-
174-
# - name: Run Test Suite
175-
# id: run-test-suite
176-
# timeout-minutes: 15
177-
# continue-on-error: true
178-
# run: |
179-
# chmod +x $GITHUB_WORKSPACE/powerpipe/tests/acceptance/run.sh
180-
# $GITHUB_WORKSPACE/powerpipe/tests/acceptance/run.sh ${{ matrix.test_block }}.bats
181-
# echo "exit_code=$(echo $?)" >> $GITHUB_OUTPUT
182-
# echo ">> here"
183-
184-
# # This job checks whether the test suite has passed or not.
185-
# # Since the exit_code is set only when the bats test suite pass,
186-
# # we have added the if-conditional block
187-
# - name: Check Test Passed/Failed
188-
# if: ${{ success() }}
189-
# continue-on-error: false
190-
# run: |
191-
# if [ ${{ steps.run-test-suite.outputs.exit_code }} -eq 0 ]; then
192-
# exit 0
193-
# else
194-
# exit 1
195-
# fi
196-
197-
# - name: Stop steampipe service
198-
# run: |
199-
# steampipe service stop
127+
- name: Set PATH
128+
run: |
129+
echo "PATH=$PATH:$HOME/build:$GTIHUB_WORKSPACE/tailpipe/tests/acceptance/lib/bats-core/libexec" >> $GITHUB_ENV
130+
131+
- name: Go install jd
132+
run: |
133+
go install github.com/josephburnett/jd@latest
134+
135+
# TODO remove this step once tailpipe and its plugins are public
136+
- name: Log in to the Container registry
137+
uses: docker/login-action@v2
138+
with:
139+
registry: ghcr.io
140+
username: ${{ secrets.GH_USERNAME }}
141+
password: ${{ secrets.GH_PAT }}
142+
143+
- name: Install Tailpipe and plugins
144+
run: |
145+
tailpipe plugin install chaos
146+
147+
- name: Run Test Suite
148+
id: run-test-suite
149+
timeout-minutes: 15
150+
continue-on-error: true
151+
run: |
152+
chmod +x $GITHUB_WORKSPACE/tailpipe/tests/acceptance/run.sh
153+
$GITHUB_WORKSPACE/tailpipe/tests/acceptance/run.sh ${{ matrix.test_block }}.bats
154+
echo "exit_code=$(echo $?)" >> $GITHUB_OUTPUT
155+
echo ">> here"
156+
157+
# This job checks whether the test suite has passed or not.
158+
# Since the exit_code is set only when the bats test suite pass,
159+
# we have added the if-conditional block
160+
- name: Check Test Passed/Failed
161+
if: ${{ success() }}
162+
continue-on-error: false
163+
run: |
164+
if [ ${{ steps.run-test-suite.outputs.exit_code }} -eq 0 ]; then
165+
exit 0
166+
else
167+
exit 1
168+
fi
200169
201170
cleanup:
202171
# let's clean up the artifacts.
@@ -205,7 +174,7 @@ jobs:
205174
# refer:
206175
# https://docs.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts#downloading-and-deleting-artifacts-after-a-workflow-run-is-complete
207176
name: Clean Up Artifacts
208-
needs: goreleaser
177+
needs: acceptance_test
209178
# if: ${{ needs.acceptance_test.result == 'success' }}
210179
runs-on: ubuntu-latest
211180
steps:

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "tests/acceptance/lib/bats-support"]
2+
path = tests/acceptance/lib/bats-support
3+
url = https://github.com/ztombol/bats-support
4+
[submodule "tests/acceptance/lib/bats-assert"]
5+
path = tests/acceptance/lib/bats-assert
6+
url = https://github.com/ztombol/bats-assert
7+
[submodule "tests/acceptance/lib/bats"]
8+
path = tests/acceptance/lib/bats
9+
url = https://github.com/sstephenson/bats

internal/collector/execution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func (e *execution) getTiming() types.TimingCollection {
5555
// TODO #timing a nice way of doing this
5656
res := e.pluginTiming
5757
if e.conversionTiming.Operation != "" {
58-
res = append(res, e.conversionTiming) //nolint: govet // TODO Timing contains sync.Mutex, find a nice way of handling this
58+
res = append(res, e.conversionTiming)
5959
}
60-
return append(res, e.executionTiming) //nolint: govet // TODO Timing contains sync.Mutex, find a nice way of handling this
60+
return append(res, e.executionTiming)
6161
}
6262

6363
// set state to complete and set end time for the execution and the conversion timing

internal/parquet/duck_db.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func newDuckDb() (*duckDb, error) {
3434
}
3535

3636
func installAndLoadExtensions(db *sql.DB) error {
37+
// set the extension directory
3738
if _, err := db.Exec(fmt.Sprintf("SET extension_directory = '%s';", filepaths.EnsurePipesDuckDbExtensionsDir())); err != nil {
3839
return fmt.Errorf("failed to set extension_directory: %w", err)
3940
}

tests/acceptance/lib/bats

Submodule bats added at 0360811

tests/acceptance/lib/bats-assert

Submodule bats-assert added at 9f88b42

tests/acceptance/lib/bats-support

Submodule bats-support added at 004e707

tests/acceptance/run-local.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
MY_PATH="`dirname \"$0\"`" # relative
4+
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
5+
6+
# TODO PSKR review all exports and remove unused ones in tailpipe
7+
export TAILPIPE_INSTALL_DIR=$(mktemp -d)
8+
export TZ=UTC
9+
export WD=$(mktemp -d)
10+
11+
trap "cd -;code=$?;rm -rf $TAILPIPE_INSTALL_DIR; exit $code" EXIT
12+
13+
cd "$WD"
14+
echo "Working directory: $WD"
15+
# setup a tailpipe installation
16+
echo "Install directory: $TAILPIPE_INSTALL_DIR"
17+
18+
# Temporarily disable 'exit on error' since we want to run the collect command and not exit if it fails
19+
set +e
20+
tailpipe collect > /dev/null 2>&1
21+
check_status=$?
22+
set -e
23+
24+
echo "Installation complete at $TAILPIPE_INSTALL_DIR"
25+
26+
# install chaos plugin
27+
tailpipe plugin install chaos
28+
echo "Installed CHAOS plugin"
29+
30+
if [ $# -eq 0 ]; then
31+
# Run all test files
32+
"$MY_PATH/run.sh"
33+
else
34+
"$MY_PATH/run.sh" "${1}"
35+
fi

tests/acceptance/run.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash -e
2+
3+
MY_PATH="`dirname \"$0\"`" # relative
4+
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
5+
6+
# trap "code=$?;rm -rf $MY_PATH/test_data/templates; exit $code" EXIT
7+
8+
# set this to the source file for development
9+
export BATS_PATH=$MY_PATH/lib/bats/bin/bats
10+
export LIB_BATS_ASSERT=$MY_PATH/lib/bats-assert
11+
export LIB_BATS_SUPPORT=$MY_PATH/lib/bats-support
12+
export TEST_DATA_DIR=$MY_PATH/test_data/templates
13+
14+
# Must have these commands for the test suite to run
15+
declare -a required_commands=("sed" "tailpipe" $BATS_PATH "rm" "mv" "cp" "mkdir" "cd" "node" "npm" "npx" "head" "wc" "find" "basename" "dirname")
16+
17+
for required_command in "${required_commands[@]}"
18+
do
19+
if [[ $(command -v $required_command | head -c1 | wc -c) -eq 0 ]]; then
20+
echo "$required_command is required for this test suite to run."
21+
exit -1
22+
fi
23+
done
24+
25+
# create a copy of the test data templates
26+
# mkdir $MY_PATH/test_data/templates
27+
# export TEST_DATA_DIR=$MY_PATH/test_data/templates
28+
# cp -R $MY_PATH/test_data/templates/* $TEST_DATA_DIR/
29+
30+
# cd $TEST_DATA_DIR
31+
32+
echo " ____ _ _ _ _____ _ "
33+
echo "/ ___|| |_ __ _ _ __| |_(_)_ __ __ _ |_ _|__ ___| |_ ___ "
34+
echo "\___ \| __/ _\` | '__| __| | '_ \ / _\` | | |/ _ \/ __| __/ __|"
35+
echo " ___) | || (_| | | | |_| | | | | (_| | | | __/\__ \ |_\__ \\"
36+
echo "|____/ \__\__,_|_| \__|_|_| |_|\__, | |_|\___||___/\__|___/"
37+
echo " |___/ "
38+
39+
export PATH=$MY_PATH/lib/bats/bin:$PATH
40+
41+
if [[ ! ${TAILPIPE_INSTALL_DIR} ]];
42+
then
43+
export TAILPIPE_INSTALL_DIR="$HOME/.tailpipe"
44+
fi
45+
46+
batversion=$(bats --version)
47+
echo $batversion
48+
echo "Running with TAILPIPE_INSTALL_DIR set to: $TAILPIPE_INSTALL_DIR"
49+
echo "Running with binary from: $(which tailpipe)"
50+
51+
if [ $# -eq 0 ]; then
52+
# Run all test files
53+
$BATS_PATH --tap $MY_PATH/test_files
54+
else
55+
$BATS_PATH --tap $MY_PATH/test_files/${1}
56+
fi
57+
58+
# Setting the exit_code, to use in the github workflow(This only gets set to 0 when the above bats test suite passes)
59+
echo "::set-output name=exit_code::$(echo $?)"

0 commit comments

Comments
 (0)