github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/git/remote_test.go (about)

     1  package git
     2  
     3  import (
     4  	"os/exec"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/tilt-dev/tilt/internal/testutils/tempdir"
    10  )
    11  
    12  func TestNormalizeGitRemoteSuffix(t *testing.T) {
    13  	assert.Equal(t, normalizeGitRemote("https://github.com/tilt-dev/tilt.git"), normalizeGitRemote("https://github.com/tilt-dev/tilt"))
    14  }
    15  
    16  func TestNormalizeGitRemoteScheme(t *testing.T) {
    17  	assert.Equal(t, normalizeGitRemote("https://github.com/tilt-dev/tilt.git"), normalizeGitRemote("ssh://github.com/tilt-dev/tilt"))
    18  }
    19  
    20  func TestNormalizeGitRemoteTrailingSlash(t *testing.T) {
    21  	assert.Equal(t, normalizeGitRemote("https://github.com/tilt-dev/tilt"), normalizeGitRemote("ssh://github.com/tilt-dev/tilt/"))
    22  }
    23  
    24  func TestNormalizedGitRemoteUsername(t *testing.T) {
    25  	assert.Equal(t, normalizeGitRemote("https://github.com/tilt-dev/tilt"), normalizeGitRemote("git@github.com:tilt-dev/tilt.git"))
    26  }
    27  
    28  func TestGitOrigin(t *testing.T) {
    29  	tf := tempdir.NewTempDirFixture(t)
    30  
    31  	err := exec.Command("git", "init", tf.Path()).Run()
    32  	if err != nil {
    33  		t.Fatalf("failed to init git repo: %+v", err)
    34  	}
    35  	err = exec.Command("git", "-C", tf.Path(), "remote", "add", "origin", "https://github.com/tilt-dev/tilt").Run()
    36  	if err != nil {
    37  		t.Fatalf("failed to set origin's url: %+v", err)
    38  	}
    39  	origin := gitOrigin(tf.Path())
    40  
    41  	// we can't just compare raw urls because of https://git-scm.com/docs/git-config#git-config-urlltbasegtinsteadOf
    42  	// e.g., circleci images set `url.ssh://git@github.com.insteadof=https://github.com`
    43  	assert.Equal(t, "//github.com/tilt-dev/tilt", normalizeGitRemote(origin))
    44  }