-
Notifications
You must be signed in to change notification settings - Fork 4
/
bundles_test.go
68 lines (51 loc) · 1.34 KB
/
bundles_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
package githosts
import (
"fmt"
"os"
"path"
"testing"
"github.com/stretchr/testify/require"
)
const (
testBundleName1 = "repo0.20200401111111.bundle"
)
func TestRenameInvalidBundle(t *testing.T) {
if os.Getenv(envGithubToken) == "" {
t.Skip("Skipping GitHub test as GITHUB_TOKEN is missing")
}
resetBackups()
backupDir := os.Getenv(envVarGitBackupDir)
dfDir := path.Join(backupDir, gitHubDomain, "go-soba", "repo0")
require.NoError(t, os.MkdirAll(dfDir, 0o755))
dfName := testBundleName1
dfPath := path.Join(dfDir, dfName)
_, err := os.OpenFile(dfPath, os.O_RDONLY|os.O_CREATE, 0o666)
require.NoError(t, err)
// run
gh, err := NewGitHubHost(NewGitHubHostInput{
APIURL: githubAPIURL,
DiffRemoteMethod: refsMethod,
BackupDir: backupDir,
Token: os.Getenv(envGithubToken),
BackupsToRetain: 1,
})
require.NoError(t, err)
gh.Backup()
// check only one bundle remains
files, err := os.ReadDir(dfDir)
require.NoError(t, err)
dfRenamed := testBundleName1 + ".invalid"
var originalFound int
var renamedFound int
for _, f := range files {
require.NotEqual(t, f.Name(), dfName, fmt.Sprintf("unexpected bundle: %s", f.Name()))
if dfName == f.Name() {
originalFound++
}
if dfRenamed == f.Name() {
renamedFound++
}
}
require.Zero(t, originalFound)
require.Equal(t, 1, renamedFound)
}