From bea4330070559ef53d6b41826465c4f7f95141b2 Mon Sep 17 00:00:00 2001 From: Debanjan Ganguly Date: Tue, 10 Sep 2024 22:19:17 +0530 Subject: [PATCH] fix: gittest server `tls: unknown certificate authority` (#638) --- testhelper/gittest/gittest.go | 2 +- testhelper/gittest/gittest_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/testhelper/gittest/gittest.go b/testhelper/gittest/gittest.go index e7d66371..323db29c 100644 --- a/testhelper/gittest/gittest.go +++ b/testhelper/gittest/gittest.go @@ -110,7 +110,7 @@ func (s *Server) GetServerCA() []byte { } func (s *Server) GetLatestCommitHash(t testing.TB, branch string) string { - cmd := exec.Command("git", "ls-remote", s.URL, fmt.Sprintf("refs/heads/%s", branch)) + cmd := exec.Command("git", "-c", "http.sslVerify=false", "ls-remote", s.URL, fmt.Sprintf("refs/heads/%s", branch)) out, err := cmd.Output() require.NoError(t, err, "should be able to run the ls-remote command") commitHash := strings.Split(string(out), "\t")[0] diff --git a/testhelper/gittest/gittest_test.go b/testhelper/gittest/gittest_test.go index fd6477e3..18ce52a7 100644 --- a/testhelper/gittest/gittest_test.go +++ b/testhelper/gittest/gittest_test.go @@ -74,6 +74,13 @@ func TestGitServer(t *testing.T) { url := s.URL require.NoError(t, exec.Command("git", "-c", "http.sslVerify=false", "clone", url, tempDir).Run(), "should be able to clone the repository") require.FileExists(t, tempDir+"/README.md", "README.md should exist in the cloned repository") + + out, err := execCmd("git", "-C", tempDir, "rev-parse", "HEAD") + require.NoError(t, err, "should be able to get the HEAD commit") + require.NotEmpty(t, out, "HEAD commit should not be empty") + + latestCommit := s.GetLatestCommitHash(t, "main") + require.Equal(t, strings.TrimSpace(out), latestCommit, "HEAD commit should match the latest commit") }) }