Commit Graph

229 Commits

Author SHA1 Message Date
Tim Hockin d76f86cb4d Fix whitespace 2025-05-02 08:01:27 -07:00
Tim Hockin ba499ade2f Make all of e2e use "local" for vars 2025-05-02 08:01:27 -07:00
AlanZhang2002 7d9699e5fc added test for same SHA and filename 2025-05-01 11:23:47 -07:00
Tim Hockin 97c0d585a8 Fix up CI for GH app tests
For now we skip
2024-09-25 12:38:45 -07:00
Nan Yu 8441240d9a Enable the GitHub app e2e test
The GitHub app e2e test requires a GitHub app to be created and
installed, and also requires a few environment variables to be set.

This commit updates the GitHub action workflow by providing the
environment variables which can be set via GitHub Secret. GitHub
Secrests cannot start with `GITHUB_`. Hence, this commit prepends
`TEST_` to the env variables.

It also updates how GitHub app private key file is set. It can be set by
either `TEST_GITHUB_APP_PRIVATE_KEY` or
`TEST_GITHUB_APP_PRIVATE_KEY_FILE`.
2024-09-25 11:51:39 -07:00
Liam Wyllie 0e2e0f0adc Add support for GitHub app authentication
Signed-off-by: Liam Wyllie <risset@mailbox.org>
2024-09-25 11:51:39 -07:00
Sam Dowell f6f7401e6b test: harden e2e image build logic
This introduces several changes to make the e2e test image logic more
robust:

- Rename IMAGE to GIT_SYNC_E2E_IMAGE to minimize accidental misuse
- Ensure that the image built by make container is the same as the image
  used by docker run
- Do not build the container if a custom image is specified

As an example, with the prior logic the following command always fails:
IMAGE="" make test
...
Unable to find image 'gcr.io/k8s-staging-git-sync/git-sync:latest' locally

Because the docker run command pulls a different image from the one
built by make container.
2024-07-16 16:07:29 -07:00
Raúl Benencia c8089abf31 test_e2e.sh: disable SC2120 for 'caller' function 2024-06-24 16:45:51 -07:00
Raúl Benencia c97fb8ac36 test_e2e.sh: revert explicitly passing parameters to 'caller'
This reverts commit d67c7c6c93.
2024-06-24 16:45:51 -07:00
Raúl Benencia 27a325e9f3 test_e2e.sh: quote $expected_depth 2024-06-24 16:45:51 -07:00
Raúl Benencia 81a4409a04 test_e2e.sh: declare restore_opts and assign separately
This avoids masking return values. Fixes SC2155. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 3200ee55f6 test_e2e.sh: replace test regex for glob match
Don't quote rhs of =~, it'll match literally rather than as a
regex. Fixes SC2076. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 9b980c479b test_e2e.sh: use mapfile to split command output
Fixes SC2207. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 81bb72f296 test_e2e.sh: add exceptions for SC2016
Fixes SC2016. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 89d568d7d2 test_e2e.sh: Quote literal { }
Fixes SC1083. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 1346a81e4d test_e2e.sh: Quote the rhs of != in [[ ]] to prevent glob matching
Fixes SC2053. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 49310e18b6 test_e2e.sh: add '-r' to 'read' to avoid mangling backslashes
Fixes SC2162. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia f41adab119 test_e2e.sh: remove useless cats
Fixes SC2002. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia bfe0a0bc17 test_e2e.sh: add quotes to to prevent word splitting
Fixes SC2046. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia e7a8600806 test_e2e.sh: remove unnecessary $ on arithmetic variables
Fixes SC2004. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia 791aecfc17 test_e2e.sh: explicitly pass parameters to 'caller' function
Fixes SC2120. Part of #891.
2024-06-24 16:45:51 -07:00
Raúl Benencia c8eabb1213 test_e2e.sh: Use index to expand FUNCNAME
Fixes SC2128. Part of #891.
2024-06-21 17:51:23 -07:00
Tim Hockin efd8ecf490 Remove e2e debug code 2024-06-19 12:30:13 -07:00
Raúl Benencia 20c26145ce test_e2e.sh: quote variables to prevent globbing and word splitting
Fixes SC2086.
2024-06-19 10:24:29 -07:00
Raúl Benencia 390f63cc6e test_e2e.sh: fully quote string sent to assert functions
Fixes SC2086. Some strings don't require to be fully quoted, but doing
so anyway to keep code consistency.
2024-06-19 10:13:58 -07:00
Tim Hockin 28394608e8 Add the idea of "env-flags"
Env-flags are "flags" that can only be set by env var (see caveat below).
All of the real flags have a corresponding env-flag (kind of, but not
really).  The real goal was to deprecate `--password` but keep the env
var as a documented interface.

This does that (though --password still works) and updates the usage and
manual.

This allows some future work to follow the pattern.  We do not register
every CLI flag as an env-flag because the help text would be
duplicative.  This probably wants a wrapper API that allows declaring of
abstract flags, with CLI, env, or both sources.

Caveat:

ACTUALLY, these still have a flag, but the flag is specially named and
hidden.  This makes testing a little easier where passing flags is
handled well but env vars is not.
2024-06-13 14:40:14 -07:00
Tim Hockin aa0f015606 Fix e2e, broken by a docker update I think
github actions fails with an error about "--ip can only be used on
user-defined subnets".  It looks like `--ip` never worked properly, but
wasn't a hard error before.

This is a simpler alternative to
11f475229692da93dff4d8a9337c5fc9cc48e51a (included below), which tried
using docker networks.  It seems to work but is complicated and can leak
resources.  Needs more work.

Instead, this commit just swaps out the `nc` response script
on the fly, rather than restarting `nc` and trying to get the same IP.

```diff
commit 11f475229692da93dff4d8a9337c5fc9cc48e51a
Good "git" signature for thockin@google.com with ED25519 key SHA256:PfQ0rwNUgsu5aRmerT0vkihWn/S3MXY3uoCPUiMdPrg
Author: Tim Hockin <thockin@google.com>
Date:   Wed Jun 12 20:12:54 2024 -0700

    debug test fail

    github actions fails with an error about "--ip can only be used on
    user-defined subnets"

diff --git a/test_e2e.sh b/test_e2e.sh
index d6ad730..b10e895 100755
--- a/test_e2e.sh
+++ b/test_e2e.sh
@@ -117,7 +117,7 @@ function assert_file_lines_ge() {

 function assert_metric_eq() {
     local val
-    val="$(curl --silent "http://localhost:$HTTP_PORT/metrics" \
+    val="$(curl --silent "http://$GITSYNC_IP:$HTTP_PORT/metrics" \
         | grep "^$1 " \
         | awk '{print $NF}')"
     if [[ "${val}" == "$2" ]]; then
@@ -138,6 +138,9 @@ function assert_fail() {
     )
 }

+DOCKER_SUBNET="192.168.0.0/24"
+GITSYNC_IP="192.168.0.254"
+
 # Helper: run a docker container.
 function docker_run() {
     RM="--rm"
@@ -148,6 +151,7 @@ function docker_run() {
         -d \
         ${RM} \
         --label git-sync-e2e="$RUNID" \
+        --network "e2e_$RUNID" \
         "$@"
     sleep 2 # wait for it to come up
 }
@@ -158,7 +162,8 @@ function docker_ip() {
         echo "usage: $0 <id>"
         return 1
     fi
-    docker inspect "$1" | jq -r .[0].NetworkSettings.IPAddress
+    docker inspect "$1" \
+        | jq -r ".[0].NetworkSettings.Networks.e2e_$RUNID.IPAddress"
 }

 function docker_kill() {
@@ -278,7 +283,8 @@ function GIT_SYNC() {
         -i \
         ${RM} \
         --label git-sync-e2e="$RUNID" \
-        --network="host" \
+        --network "e2e_$RUNID" \
+        --ip "$GITSYNC_IP" \
         -u git-sync:$(id -g) `# rely on GID, triggering "dubious ownership"` \
         -v "$ROOT":"$ROOT":rw \
         -v "$REPO":"$REPO":ro \
@@ -308,6 +314,9 @@ function remove_containers() {
         | while read CTR; do
             docker kill "$CTR" >/dev/null
         done
+    docker network prune -f \
+        --filter label=git-sync-e2e \
+        >/dev/null
 }

 #
@@ -2515,7 +2524,7 @@ function e2e::expose_http() {
     # do nothing, just wait for the HTTP to come up
     for i in $(seq 1 5); do
         sleep 1
-        if curl --silent --output /dev/null http://localhost:$HTTP_PORT; then
+        if curl --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT"; then
             break
         fi
         if [[ "$i" == 5 ]]; then
@@ -2524,23 +2533,23 @@ function e2e::expose_http() {
     done

     # check that health endpoint fails
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT) -ne 503 ]] ; then
-        fail "health endpoint should have failed: $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT)"
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT") -ne 503 ]] ; then
+        fail "health endpoint should have failed: $(curl --write-out %{http_code} --silent --output /dev/null http://$GITSYNC_IP:$HTTP_PORT)"
     fi
     wait_for_sync "${MAXWAIT}"

     # check that health endpoint is alive
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT") -ne 200 ]] ; then
         fail "health endpoint failed"
     fi

     # check that the metrics endpoint exists
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT/metrics) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT/metrics") -ne 200 ]] ; then
         fail "metrics endpoint failed"
     fi

     # check that the pprof endpoint exists
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT/debug/pprof/) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT/debug/pprof/") -ne 200 ]] ; then
         fail "pprof endpoint failed"
     fi
 }
@@ -2568,7 +2577,7 @@ function e2e::expose_http_after_restart() {
     # do nothing, just wait for the HTTP to come up
     for i in $(seq 1 5); do
         sleep 1
-        if curl --silent --output /dev/null http://localhost:$HTTP_PORT; then
+        if curl --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT"; then
             break
         fi
         if [[ "$i" == 5 ]]; then
@@ -2579,7 +2588,7 @@ function e2e::expose_http_after_restart() {
     sleep 2 # wait for first loop to confirm synced

     # check that health endpoint is alive
-    if [[ $(curl --write-out %{http_code} --silent --output /dev/null http://localhost:$HTTP_PORT) -ne 200 ]] ; then
+    if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://$GITSYNC_IP:$HTTP_PORT") -ne 200 ]] ; then
         fail "health endpoint failed"
     fi
     assert_link_exists "$ROOT/link"
@@ -3503,6 +3512,12 @@ function run_test() {
         set -o errexit
         set -o nounset
         set -o pipefail
+        docker network prune -f \
+            --filter label=git-sync-e2e \
+            >/dev/null
+        docker network create "e2e_$RUNID" \
+            --subnet "$DOCKER_SUBNET" \
+            --label git-sync-e2e="$RUNID"
         "$@"
     )
     eval "$retvar=$?"
```
2024-06-13 12:30:11 -07:00
Tim Hockin 6ef292034e Log tool versions in e2e 2024-06-13 12:30:11 -07:00
Tim Hockin f521da5548 Add e2e for ssh:// URLs 2024-04-04 16:40:32 -07:00
Tim Hockin 5e4ceb1b73 Add '-F none' to e2e git SSH command for weird environments 2024-01-16 17:25:05 -08:00
Tim Hockin d5c61f7ad1 Try not to log credentials in repo URL
This extracts the username and password from the URL and replaces it
with the bare URL, using the usual credential mechanism for user/pass.
2023-12-14 10:12:26 -08:00
Tim Hockin 083d8dda85 Simplify inner loop: just fetch $ref
Old way:
  - ls-remote $ref $ref^{} and parse
  - compare to current
  - if changed, fetch
  - update worktree

New way:
  - fetch $ref
  - compare to current
  - if change, update worktree
2023-12-08 18:25:00 -08:00
Tim Hockin 9a806c09cb Bug: links are relative to linkdir, not rootdir 2023-12-08 18:04:24 -08:00
Tim Hockin 2639ff475d e2e: use global 'user.email' config 2023-10-14 15:55:00 -07:00
Tim Hockin 83bd660494 Recover if wrong worktree HEAD 2023-10-14 15:55:00 -07:00
Tim Hockin befdbfff31 Remove errant use of --period with --one-time 2023-10-14 11:29:18 -07:00
Tim Hockin 1a5daeaf43 Add e2e case for missing worktree after crash 2023-10-14 11:29:12 -07:00
Aleksandar Markovski ff51ca92dc fix: infinite bad loop caused by unexpected worktree directory removal 2023-10-13 13:20:54 -07:00
Tim Hockin 162e543e05 Add --credential flag to spec multiple user/pass
* New flag is a JSON-encoded struct.
* Add test case for multiple HTTP passwd.
2023-10-08 14:46:41 -07:00
Tim Hockin 4ccf0633fb Deprecate --ssh - it's not really needed
As long as a repo uses SSH transport (user@host:path or ssh://...), SSH
is active.  This is true for the main repo or submodules.
2023-09-27 13:32:15 -07:00
Tim Hockin 32c3a0c2a7 e2e: Add assert_fail and simplify fail cases 2023-09-21 12:48:59 -07:00
Tim Hockin 627fe23a9a e2e: Always pre-write FUNCNAME into repo/file
This removes a few LOC from many cases
2023-09-21 09:09:58 -07:00
Tim Hockin 66e0ba3562 e2e: merge SSH fail and success cases 2023-09-20 14:30:28 -07:00
Tim Hockin a8d5675e1d Add e2e for password-file 2023-09-20 12:46:13 -07:00
Tim Hockin d4244a3424 e2e: reorder some flags for clarity 2023-09-20 09:31:15 -07:00
Tim Hockin 96b8e8a4fc Remove redundant username/password auth test
The HTTP test covers this without needing a hacky git command.
2023-09-20 09:31:15 -07:00
Tim Hockin 8310ee9ee8 Auth tests really only need to sync once
Except for URL tests which prove resilience to failure.
2023-09-20 09:31:15 -07:00
Tim Hockin 86725cb85e Reorder tests to put auth together
No other changes
2023-09-20 09:31:15 -07:00
Tim Hockin af6b96ab74 Add e2e for username/password over HTTP 2023-09-19 14:57:41 -07:00
Tim Hockin 11b8d151d0 Clean up submodule cases to be a bit more readable 2023-09-19 13:40:40 -07:00