forked from thoughtworks/talisman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
talisman_internal_test.go
67 lines (52 loc) · 2 KB
/
talisman_internal_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"github.com/spf13/afero"
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParsingShasFromStdIn(t *testing.T) {
file, err := ioutil.TempFile(os.TempDir(), "mockStdin")
if err != nil {
panic(err)
}
defer os.Remove(file.Name())
defer file.Close()
file.WriteString("localRef localSha remoteRef remoteSha")
file.Seek(0, 0)
_, oldSha, _, newSha := readRefAndSha(file)
assert.Equal(t, "localSha", oldSha, "oldSha did not equal 'localSha', got: %s", oldSha)
assert.Equal(t, "remoteSha", newSha, "newSha did not equal 'remoteSha', got: %s", newSha)
}
func Test_validateGitExecutable(t *testing.T) {
t.Run("given operating systems is windows", func(t *testing.T) {
operatingSystem := "windows"
os.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC")
t.Run("should return error if git executable exists in current directory", func(t *testing.T) {
fs := afero.NewMemMapFs()
gitExecutable := "git.exe"
afero.WriteFile(fs, gitExecutable, []byte("git executable"), 0700)
err := validateGitExecutable(fs, operatingSystem)
assert.EqualError(t, err, "not allowed to have git executable located in repository: git.exe")
})
t.Run("should return nil if git executable does not exist in current directory", func(t *testing.T) {
err := validateGitExecutable(afero.NewMemMapFs(), operatingSystem)
assert.NoError(t, err)
})
})
t.Run("given operating systems is linux", func(t *testing.T) {
operatingSystem := "linux"
t.Run("should return nil if git executable exists in current directory", func(t *testing.T) {
fs := afero.NewMemMapFs()
gitExecutable := "git.exe"
afero.WriteFile(fs, gitExecutable, []byte("git executable"), 0700)
err := validateGitExecutable(fs, operatingSystem)
assert.NoError(t, err)
})
t.Run("should return nil if git executable does not exist in current directory", func(t *testing.T) {
err := validateGitExecutable(afero.NewMemMapFs(), operatingSystem)
assert.NoError(t, err)
})
})
}