Skip to content

Commit

Permalink
test: do not run acceptance tests as root
Browse files Browse the repository at this point in the history
  • Loading branch information
hekmekk committed Jun 11, 2023
1 parent ca270e4 commit 084c606
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
4 changes: 4 additions & 0 deletions acceptance-tests.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ COPY --from=git-team /go/bin/git-team /usr/local/bin/git-team

WORKDIR /

ENV USERNAME git-team-acceptance-test
RUN adduser -D ${USERNAME}
USER ${USERNAME}

ENTRYPOINT ["bash", "/usr/local/bin/bats"]
6 changes: 3 additions & 3 deletions acceptance-tests/disable_global.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setup() {
}

teardown() {
rm /root/.gitconfig
rm /home/git-team-acceptance-test/.gitconfig
}

@test "git-team: (scope: global) disable should disable a previously enabled git-team" {
Expand Down Expand Up @@ -67,9 +67,9 @@ teardown() {
/usr/local/bin/git-team enable 'A <a@x.y>' 'B <b@x.y>'
/usr/local/bin/git-team disable

run bash -c "ls -la /root/.git-team/commit-templates/global/COMMIT_TEMPLATE"
run bash -c "ls -la /home/git-team-acceptance-test/.git-team/commit-templates/global/COMMIT_TEMPLATE"
assert_failure 1
assert_line "ls: /root/.git-team/commit-templates/global/COMMIT_TEMPLATE: No such file or directory"
assert_line "ls: /home/git-team-acceptance-test/.git-team/commit-templates/global/COMMIT_TEMPLATE: No such file or directory"
}

@test "git-team: (scope: global) disable should treat a previously disabled git-team idempotently" {
Expand Down
6 changes: 3 additions & 3 deletions acceptance-tests/disable_repo_local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ teardown() {
cd -
rm -rf $REPO_PATH

rm /root/.gitconfig
rm /home/git-team-acceptance-test/.gitconfig
}

@test "git-team: (scope: repo-local) disable should disable a previously enabled git-team" {
Expand Down Expand Up @@ -80,9 +80,9 @@ teardown() {
/usr/local/bin/git-team enable 'A <a@x.y>' 'B <b@x.y>'
/usr/local/bin/git-team disable

run bash -c "ls -la /root/.git-team/commit-templates/repo-local/$REPO_CHECKSUM"
run bash -c "ls -la /home/git-team-acceptance-test/.git-team/commit-templates/repo-local/$REPO_CHECKSUM"
assert_failure 1
assert_line "ls: /root/.git-team/commit-templates/repo-local/$REPO_CHECKSUM: No such file or directory"
assert_line "ls: /home/git-team-acceptance-test/.git-team/commit-templates/repo-local/$REPO_CHECKSUM: No such file or directory"
}

@test "git-team: (scope: repo-local) disable should treat a previously disabled git-team idempotently" {
Expand Down
12 changes: 6 additions & 6 deletions acceptance-tests/enable_global.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ teardown() {
}

@test "git-team: (scope: global) enable should not set the git-team hooks path as the previous hooks path" {
git config --global core.hooksPath "/root/.git-team/hooks"
git config --global core.hooksPath "/home/git-team-acceptance-test/.git-team/hooks"

/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>'

Expand Down Expand Up @@ -73,17 +73,17 @@ teardown() {
@test "git-team: (scope: global) enable should enable the prepare-commit-msg hook" {
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && git config --global core.hooksPath"
assert_success
assert_line '/root/.git-team/hooks'
assert_line '/home/git-team-acceptance-test/.git-team/hooks'
}

@test "git-team: (scope: global) enable should set a commit template" {
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && git config --global commit.template"
assert_success
assert_line '/root/.git-team/commit-templates/global/COMMIT_TEMPLATE'
assert_line '/home/git-team-acceptance-test/.git-team/commit-templates/global/COMMIT_TEMPLATE'
}

@test "git-team: (scope: global) enable should provision the commit template" {
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && cat /root/.git-team/commit-templates/global/COMMIT_TEMPLATE"
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && cat /home/git-team-acceptance-test/.git-team/commit-templates/global/COMMIT_TEMPLATE"
assert_success
assert_line --index 0 'Co-authored-by: A <a@x.y>'
assert_line --index 1 'Co-authored-by: Ad-hoc <adhoc@tmp.se>'
Expand All @@ -92,15 +92,15 @@ teardown() {
}

@test "git-team: (scope: global) enable 'all via -A' should provision the commit template" {
run bash -c "/usr/local/bin/git-team enable -A &>/dev/null && cat /root/.git-team/commit-templates/global/COMMIT_TEMPLATE"
run bash -c "/usr/local/bin/git-team enable -A &>/dev/null && cat /home/git-team-acceptance-test/.git-team/commit-templates/global/COMMIT_TEMPLATE"
assert_success
assert_line --index 0 'Co-authored-by: A <a@x.y>'
assert_line --index 1 'Co-authored-by: B <b@x.y>'
assert_line --index 2 'Co-authored-by: C <c@x.y>'
}

@test "git-team: (scope: global) enable 'all via --all' should provision the commit template" {
run bash -c "/usr/local/bin/git-team enable --all &>/dev/null && cat /root/.git-team/commit-templates/global/COMMIT_TEMPLATE"
run bash -c "/usr/local/bin/git-team enable --all &>/dev/null && cat /home/git-team-acceptance-test/.git-team/commit-templates/global/COMMIT_TEMPLATE"
assert_success
assert_line --index 0 'Co-authored-by: A <a@x.y>'
assert_line --index 1 'Co-authored-by: B <b@x.y>'
Expand Down
12 changes: 6 additions & 6 deletions acceptance-tests/enable_repo_local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ teardown() {
}

@test "git-team: (scope: repo-local) enable should not set the git-team hooks path as the previous hooks path" {
git config --local core.hooksPath "/root/.git-team/hooks"
git config --local core.hooksPath "/home/git-team-acceptance-test/.git-team/hooks"

/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>'

Expand Down Expand Up @@ -86,17 +86,17 @@ teardown() {
@test "git-team: (scope: repo-local) enable should set the prepare-commit-msg hook" {
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && git config --local core.hooksPath"
assert_success
assert_line '/root/.git-team/hooks'
assert_line '/home/git-team-acceptance-test/.git-team/hooks'
}

@test "git-team: (scope: repo-local) enable should set the commit template" {
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && git config --local commit.template"
assert_success
assert_line "/root/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
assert_line "/home/git-team-acceptance-test/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
}

@test "git-team: (scope: repo-local) enable should provision the commit template" {
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && cat /root/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
run bash -c "/usr/local/bin/git-team b a c 'Ad-hoc <adhoc@tmp.se>' &>/dev/null && cat /home/git-team-acceptance-test/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
assert_success
assert_line --index 0 'Co-authored-by: A <a@x.y>'
assert_line --index 1 'Co-authored-by: Ad-hoc <adhoc@tmp.se>'
Expand All @@ -105,15 +105,15 @@ teardown() {
}

@test "git-team: (scope: repo-local) enable 'all via -A' should provision the commit template" {
run bash -c "/usr/local/bin/git-team enable -A &>/dev/null && cat /root/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
run bash -c "/usr/local/bin/git-team enable -A &>/dev/null && cat /home/git-team-acceptance-test/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
assert_success
assert_line --index 0 'Co-authored-by: A <a@x.y>'
assert_line --index 1 'Co-authored-by: B <b@x.y>'
assert_line --index 2 'Co-authored-by: C <c@x.y>'
}

@test "git-team: (scope: repo-local) enable 'all via --all' should provision the commit template" {
run bash -c "/usr/local/bin/git-team enable --all &>/dev/null && cat /root/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
run bash -c "/usr/local/bin/git-team enable --all &>/dev/null && cat /home/git-team-acceptance-test/.git-team/commit-templates/repo-local/$REPO_CHECKSUM/COMMIT_TEMPLATE"
assert_success
assert_line --index 0 'Co-authored-by: A <a@x.y>'
assert_line --index 1 'Co-authored-by: B <b@x.y>'
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/use_cases_disabled.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ teardown() {
cd -
rm -rf $REPO_PATH

rm /root/.gitconfig
rm /home/git-team-acceptance-test/.gitconfig
}

@test "use case: when git-team is disabled, a merge commit should not have co-authors injected" {
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/use_cases_global.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ teardown() {
cd -
rm -rf $REPO_PATH

rm /root/.gitconfig
rm /home/git-team-acceptance-test/.gitconfig
}

@test "use case: (scope: global) an existing repo-local git hook should be respected - commit-msg" {
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/use_cases_repo_local.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ teardown() {
cd -
rm -rf $REPO_PATH

rm /root/.gitconfig
rm /home/git-team-acceptance-test/.gitconfig
}

@test "use case: (scope: repo-local) an existing repo-local git hook should be respected - commit msg" {
Expand Down

0 comments on commit 084c606

Please sign in to comment.