Skip to content

Commit

Permalink
feat: method for fetching latest commit from gittest server (#636)
Browse files Browse the repository at this point in the history
Co-authored-by: Aris Tzoumas <atzoumas@rudderstack.com>
  • Loading branch information
debanjan97 and atzoum authored Sep 10, 2024
1 parent 6aef6cc commit 7d4f518
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rudderlabs/rudder-go-kit

go 1.22.5
go 1.22.7

replace github.com/gocql/gocql => github.com/scylladb/gocql v1.14.2

Expand Down
8 changes: 8 additions & 0 deletions testhelper/gittest/gittest.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ func (s *Server) GetServerCA() []byte {
return getServerCA(s.Server)
}

func (s *Server) GetLatestCommitHash(t testing.TB, branch string) string {
cmd := exec.Command("git", "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]
return commitHash
}

func getServerCA(server *httptest.Server) []byte {
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: server.TLS.Certificates[0].Certificate[0]})
}
Expand Down
8 changes: 8 additions & 0 deletions testhelper/gittest/gittest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -57,6 +58,13 @@ func TestGitServer(t *testing.T) {

out, err = execCmd("git", "-C", tempDir, "push", "origin", "v1.0.0")
require.NoErrorf(t, err, "should be able to push the tag: %s", out)

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, "develop")
require.Equal(t, strings.TrimSpace(out), latestCommit, "HEAD commit should match the latest commit")
})

t.Run("https", func(t *testing.T) {
Expand Down

0 comments on commit 7d4f518

Please sign in to comment.