-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathRepository_test.go
More file actions
74 lines (66 loc) · 2.01 KB
/
Copy pathRepository_test.go
File metadata and controls
74 lines (66 loc) · 2.01 KB
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
68
69
70
71
72
73
74
package db
import (
"math/rand"
"os"
"path"
"testing"
"github.com/semaphoreui/semaphore/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRepository_GetSchema(t *testing.T) {
repo := Repository{GitURL: "https://example.com/hello/world"}
schema := repo.GetType()
assert.Equal(t, RepositoryHTTP, schema)
}
func TestRepository_GetType_WindowsLocalPath(t *testing.T) {
assert.Equal(t, RepositoryLocal, Repository{GitURL: `D:\repo`}.GetType())
assert.Equal(t, RepositoryLocal, Repository{GitURL: `D:/repo`}.GetType())
assert.Equal(t, RepositoryLocal, Repository{GitURL: `D:`}.GetType())
assert.Equal(t, RepositoryLocal, Repository{GitURL: `\\server\share`}.GetType())
}
func TestRepository_ClearCache(t *testing.T) {
util.Config = &util.ConfigType{
TmpPath: path.Join(os.TempDir(), util.RandString(rand.Intn(10-4)+4)),
}
repoDir := path.Join(util.Config.TmpPath, "project_0", "repository_123_55")
err := os.MkdirAll(repoDir, 0755)
require.NoError(t, err)
repo := Repository{ID: 123}
err = repo.ClearCache()
require.NoError(t, err)
_, err = os.Stat(repoDir)
require.Error(t, err, "repo directory not deleted")
assert.True(t, os.IsNotExist(err))
}
func TestRepository_GetGitURL(t *testing.T) {
for _, v := range []struct {
Repository Repository
ExpectedGitUrl string
}{
{
Repository: Repository{GitURL: "https://github.com/user/project.git", SSHKey: &AccessKey{
Type: AccessKeyLoginPassword,
LoginPassword: LoginPassword{
Login: "login",
Password: "password",
},
},
},
ExpectedGitUrl: "https://login:password@github.com/user/project.git",
},
{
Repository: Repository{GitURL: "https://github.com/user/project.git", SSHKey: &AccessKey{
Type: AccessKeyLoginPassword,
LoginPassword: LoginPassword{
Password: "password",
},
},
},
ExpectedGitUrl: "https://password@github.com/user/project.git",
},
} {
gitUrl := v.Repository.GetGitURL(false)
assert.Equal(t, v.ExpectedGitUrl, gitUrl, "wrong gitUrl")
}
}