File: remote_test.go

package info (click to toggle)
gittuf 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,692 kB
  • sloc: python: 85; makefile: 58; sh: 1
file content (55 lines) | stat: -rw-r--r-- 1,318 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright The gittuf Authors
// SPDX-License-Identifier: Apache-2.0

package gitinterface

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestRemote(t *testing.T) {
	tmpDir := t.TempDir()
	repo := CreateTestGitRepository(t, tmpDir, false)

	output, err := repo.executor("remote").executeString()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, "", output) // no output because there are no remotes

	remoteName := "origin"
	remoteURL := "git@example.com:repo.git"

	// Test AddRemote
	err = repo.AddRemote(remoteName, remoteURL)
	assert.Nil(t, err)

	output, err = repo.executor("remote", "-v").executeString()
	if err != nil {
		t.Fatal(err)
	}

	expectedOutput := fmt.Sprintf("%s\t%s (fetch)\n%s\t%s (push)", remoteName, remoteURL, remoteName, remoteURL)
	assert.Equal(t, expectedOutput, output)

	// Test GetRemoteURL
	returnedRemoteURL, err := repo.GetRemoteURL(remoteName)
	assert.Nil(t, err)
	assert.Equal(t, remoteURL, returnedRemoteURL)

	_, err = repo.GetRemoteURL("does-not-exist")
	assert.ErrorContains(t, err, "No such remote")

	// Test RemoveRemote
	err = repo.RemoveRemote(remoteName)
	assert.Nil(t, err)

	output, err = repo.executor("remote").executeString()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, "", output) // no output because there are no remotes
}