-
Notifications
You must be signed in to change notification settings - Fork 1
/
bunch_test.go
68 lines (51 loc) · 1.61 KB
/
bunch_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 main
import (
"github.com/kr/s3/s3util"
"github.com/stretchr/testify/assert"
"os"
"os/exec"
"testing"
)
func Test_loadS3CredentialsNotSet(t *testing.T) {
loadS3Credentials()
assert.Equal(t, options.S3Key, "")
assert.Equal(t, options.S3Secret, "")
assert.Equal(t, options.S3Bucket, "")
}
func Test_loadS3CredentialsSet(t *testing.T) {
os.Setenv("S3_KEY", "key")
os.Setenv("S3_SECRET", "secret")
os.Setenv("S3_BUCKET", "bucket")
loadS3Credentials()
assert.Equal(t, options.S3Key, "key")
assert.Equal(t, options.S3Secret, "secret")
assert.Equal(t, options.S3Bucket, "bucket")
}
func Test_setS3Credentials(t *testing.T) {
os.Setenv("S3_KEY", "key")
os.Setenv("S3_SECRET", "secret")
os.Setenv("S3_BUCKET", "bucket")
loadS3Credentials()
setS3Credentials()
assert.Equal(t, s3util.DefaultConfig.AccessKey, "key")
assert.Equal(t, s3util.DefaultConfig.SecretKey, "secret")
}
func Test_expandPathArguments(t *testing.T) {
options.Path = "~/path"
options.Manifest = "~/manifest"
expandPathArguments()
assert.Equal(t, options.Path, os.Getenv("HOME")+"/path")
assert.Equal(t, options.Manifest, os.Getenv("HOME")+"/manifest")
}
func Test_extractDirectory(t *testing.T) {
assert.Equal(t, extract("archive", "/tmp"), false)
exec.Command("rm", "-rf", "/tmp/out").Start()
assert.Equal(t, extract("archive", "/tmp/out"), false)
exec.Command("rm", "-rf", "/tmp/out").Start()
assert.Equal(t, extract("./test/archive.tar.gz", "/tmp/out"), true)
}
func Test_writeCacheFile(t *testing.T) {
os.Remove("/tmp/.bunch")
assert.Equal(t, writeCacheFile("/tmp"), true)
assert.Equal(t, writeCacheFile("/foo"), false)
}