From c386fe42814ea7755dc67a6d60d9cf6525179c19 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Tue, 8 Aug 2023 16:08:32 +1400
Subject: [PATCH 06/11] add testcases for inspect images by digest after
 restarting isulad

Signed-off-by: zhongtao <zhongtao17@huawei.com>
---
 CI/test_cases/image_cases/image_digest.sh | 28 ++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/CI/test_cases/image_cases/image_digest.sh b/CI/test_cases/image_cases/image_digest.sh
index a7cb594a..e30f29f0 100755
--- a/CI/test_cases/image_cases/image_digest.sh
+++ b/CI/test_cases/image_cases/image_digest.sh
@@ -26,6 +26,7 @@ function test_image_with_digest()
 {
   local ret=0
   local image="busybox"
+  local image2="ubuntu"
   local image_digest="busybox@sha256:5cd3db04b8be5773388576a83177aff4f40a03457a63855f4b9cbe30542b9a43"
   local test="pull && inspect && tag image with digest test => (${FUNCNAME[@]})"
 
@@ -61,15 +62,36 @@ function test_image_with_digest()
   isula rm -f test
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to rm container" && ((ret++))
 
-  isula inspect -f '{{.image.repo_tags}}' ${image} | grep "${image}:latest"
-  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - invalid image repo tags: ${image}" && ((ret++))
-
   isula rmi ${image_digest}
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to remove image ${image_digest}" && ((ret++))
 
   isula rmi ${image}:digest_test
   [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to remove image ${image}:digest_test" && ((ret++))
 
+  isula inspect -f '{{.image.repo_tags}}' ${image_digest} | grep "${image}:digest_test"
+  [[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - image digest delete error: ${image_digest}" && ((ret++))
+
+  isula pull docker.io/library/${image2}:latest
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pull image: ${image2}" && return ${FAILURE}
+
+  digest=$(isula inspect "${image2}:latest" | grep "@sha256" | awk -F"\"" '{print $2}')
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to get digest for: ${image2}" && return ${FAILURE}
+
+  isula inspect $digest
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to inspect ${image2} by digest" && return ${FAILURE}
+
+  check_valgrind_log
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stop isulad failed" && ((ret++))
+
+  start_isulad_with_valgrind
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - start isulad failed" && ((ret++))
+
+  isula inspect $digest
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to inspect ${image2} by digest" && return ${FAILURE}
+
+  isula rmi ${image2}:latest
+  [[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to remove image ${image2}" && ((ret++))
+
   msg_info "${test} finished with return ${ret}..."
   return ${ret}
 }
-- 
2.25.1

