Skip to content

Commit 7199402

Browse files
committed
Improve e2e tests and configs for gptcommit
- Add end-to-end tests for the install script, git hook, config list, get, set and delete commands, and version
1 parent 8758ddc commit 7199402

File tree

6 files changed

+80
-1
lines changed

6 files changed

+80
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4949

5050
- run: just ${{ matrix.just_goals || 'build test' }}
51+
env:
52+
GPTCOMMIT__OPENAI__API_KEY: ${{ secrets.GPTCOMMIT__OPENAI__API_KEY }}
5153

5254
lint:
5355
runs-on: ubuntu-latest

Justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ release:
2121
install:
2222
cargo install --path .
2323

24-
test *args:
24+
e2e: install
25+
sh -eux -c 'for i in ./e2e/test_*.sh ; do sh -x $i ; done'
26+
27+
test *args: e2e
2528
cargo test
2629
alias t := test
2730

e2e/test_config_list_get_set.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
gptcommit config list
5+
# assert is valid TOML
6+
7+
gptcommit config get openai.model
8+
# assert default = text-davinci-003
9+
gptcommit config set openai.model foo
10+
gptcommit config get openai.model
11+
# assert is foo
12+
13+
gptcommit config delete openai.model
14+
gptcommit config get openai.model
15+
# back to default

e2e/test_githook.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
(
5+
mkdir test_dir_foo4
6+
cd test_dir_foo4
7+
git init
8+
9+
GPTCOMMIT__OPENAI__MODEL="text-ada-001" \
10+
gptcommit prepare-commit-msg \
11+
--git-diff-content ../tests/data/example_1.diff \
12+
--commit-msg-file /dev/stdout \
13+
--commit-source ""
14+
)
15+
rm -rf test_dir_foo4 ;

e2e/test_install.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
(
5+
mkdir test_dir_foo
6+
cd test_dir_foo
7+
git init
8+
gptcommit install
9+
10+
# assert that git hook is installed
11+
gptcommit install
12+
# assert still works
13+
)
14+
rm -rf test_dir_foo ;
15+
16+
#############################
17+
18+
(
19+
mkdir test_dir_foo2
20+
cd test_dir_foo2
21+
git init
22+
mkdir a
23+
cd a
24+
gptcommit install
25+
)
26+
rm -rf test_dir_foo2
27+
28+
#############################
29+
30+
(
31+
mkdir test_dir_foo3
32+
cd test_dir_foo3
33+
# no git init
34+
gptcommit install ;
35+
)
36+
rm -rf test_dir_foo3

e2e/test_version.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
gptcommit --version
5+
# assert matches version in Cargo.toml
6+
7+
gptcommit --help
8+

0 commit comments

Comments
 (0)