-
Notifications
You must be signed in to change notification settings - Fork 4
/
gitlab_test.go
87 lines (75 loc) · 3 KB
/
gitlab_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package githosts
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
const (
gitlabEnvVarToken = "GITLAB_TOKEN"
gitlabEnvVarProjectMinAccessLevel = "GITLAB_PROJECT_MIN_ACCESS_LEVEL"
gitlabEnvVarAPIUrl = "GITLAB_APIURL"
)
func TestPublicGitLabRepositoryBackupCloneMethod(t *testing.T) {
resetBackups()
if os.Getenv(gitlabEnvVarToken) == "" {
t.Skip("Skipping GitLab test as GITLAB_TOKEN is missing")
}
resetGlobals()
envBackup := backupEnvironmentVariables()
defer restoreEnvironmentVariables(envBackup)
unsetEnvVars([]string{envVarGitBackupDir, gitlabEnvVarToken})
backupDIR := os.Getenv(envVarGitBackupDir)
gl, err := NewGitLabHost(NewGitLabHostInput{
APIURL: gitlabAPIURL,
DiffRemoteMethod: cloneMethod,
BackupDir: backupDIR,
Token: os.Getenv(gitlabEnvVarToken),
})
require.NoError(t, err)
gl.Backup()
expectedSubProjectOnePath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-one")
expectedSubProjectTwoPath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-two")
require.DirExists(t, expectedSubProjectOnePath)
require.DirExists(t, expectedSubProjectTwoPath)
projectOneEntries, err := dirContents(expectedSubProjectOnePath)
require.NoError(t, err)
require.Len(t, projectOneEntries, 1)
require.Contains(t, projectOneEntries[0].Name(), "soba-sub-project-one.")
projectTwoEntries, err := dirContents(expectedSubProjectTwoPath)
require.NoError(t, err)
require.Len(t, projectTwoEntries, 1)
require.Contains(t, projectTwoEntries[0].Name(), "soba-sub-project-two.")
}
func TestPublicGitLabRepositoryBackupRefsMethod(t *testing.T) {
resetBackups()
if os.Getenv(gitlabEnvVarToken) == "" {
t.Skip("Skipping GitLab test as GITLAB_TOKEN is missing")
}
resetGlobals()
envBackup := backupEnvironmentVariables()
defer restoreEnvironmentVariables(envBackup)
unsetEnvVars([]string{envVarGitBackupDir, gitlabEnvVarToken})
backupDIR := os.Getenv(envVarGitBackupDir)
gl, err := NewGitLabHost(NewGitLabHostInput{
APIURL: gitlabAPIURL,
DiffRemoteMethod: refsMethod,
BackupDir: backupDIR,
Token: os.Getenv(gitlabEnvVarToken),
LogLevel: 1,
})
require.NoError(t, err)
gl.Backup()
expectedSubProjectOnePath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-one")
expectedSubProjectTwoPath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-two")
require.DirExists(t, expectedSubProjectOnePath)
require.DirExists(t, expectedSubProjectTwoPath)
projectOneEntries, err := dirContents(expectedSubProjectOnePath)
require.NoError(t, err)
require.Len(t, projectOneEntries, 1)
require.Contains(t, projectOneEntries[0].Name(), "soba-sub-project-one.")
projectTwoEntries, err := dirContents(expectedSubProjectTwoPath)
require.NoError(t, err)
require.Len(t, projectTwoEntries, 1)
require.Contains(t, projectTwoEntries[0].Name(), "soba-sub-project-two.")
}