]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add test for Redis storage with password
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 12 Jul 2021 11:51:50 +0000 (13:51 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 12 Jul 2021 20:42:43 +0000 (22:42 +0200)
test/suites/secondary_redis.bash

index a84a69c3b0ae79978131e96b9220d0588995d540..076f43619a7d94006497b6bf7df106af898b9d12 100644 (file)
@@ -11,6 +11,7 @@ SUITE_secondary_redis_PROBE() {
 
 start_redis_server() {
     local port="$1"
+    local password="${2:-}"
 
     redis-server --bind localhost --port "${port}" >/dev/null &
     # Wait for server start.
@@ -19,6 +20,10 @@ start_redis_server() {
         sleep 0.1
         i=$((i + 1))
     done
+
+    if [ -n "${password}" ]; then
+        redis-cli -p "${port}" config set requirepass "${password}" &>/dev/null
+    fi
 }
 
 SUITE_secondary_redis_SETUP() {
@@ -32,7 +37,7 @@ expect_number_of_redis_cache_entries() {
     local url=$2
     local actual
 
-    actual=$(redis-cli -u "$url" keys "ccache:*" | wc -l)
+    actual=$(redis-cli -u "$url" keys "ccache:*" 2>/dev/null | wc -l)
     if [ "$actual" -ne "$expected" ]; then
         test_failed_internal "Found $actual (expected $expected) entries in $url"
     fi
@@ -69,4 +74,36 @@ SUITE_secondary_redis() {
     expect_stat 'cache miss' 1
     expect_stat 'files in cache' 0
     expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
+
+    # -------------------------------------------------------------------------
+    TEST "Password"
+
+    port=7777
+    password=secret
+    redis_url="redis://${password}@localhost:${port}"
+    export CCACHE_SECONDARY_STORAGE="${redis_url}"
+
+    start_redis_server "${port}" "${password}"
+
+    $CCACHE_COMPILE -c test.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+    expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
+
+    $CCACHE_COMPILE -c test.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+    expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
+
+    $CCACHE -C >/dev/null
+    expect_stat 'files in cache' 0
+    expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
+
+    $CCACHE_COMPILE -c test.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 0
+    expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
 }