-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig_test.go
More file actions
60 lines (51 loc) · 1.72 KB
/
config_test.go
File metadata and controls
60 lines (51 loc) · 1.72 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
package conf
import (
"os"
"path/filepath"
"testing"
"github.com/drycc/builder/pkg/sys"
"github.com/stretchr/testify/assert"
)
func TestGetStorageParams(t *testing.T) {
env := sys.NewFakeEnv()
env.Envs = map[string]string{
"DRYCC_STORAGE_LOOKUP": "path",
"DRYCC_STORAGE_BUCKET": "builder",
"DRYCC_STORAGE_ENDPOINT": "http://localhost:8088",
"DRYCC_STORAGE_ACCESSKEY": "admin",
"DRYCC_STORAGE_SECRETKEY": "adminpass",
}
params, err := GetStorageParams(env)
if err != nil {
t.Errorf("received error while retrieving storage params: %v", err)
}
assert.Equal(t, params["forcepathstyle"], "true", "forcepathstyle")
assert.Equal(t, params["regionendpoint"], "http://localhost:8088", "region endpoint")
assert.Equal(t, params["region"], "localhost", "region")
assert.Equal(t, params["bucket"], "builder", "bucket")
assert.Equal(t, params["accesskey"], "admin", "accesskey")
assert.Equal(t, params["secretkey"], "adminpass", "secretkey")
}
func TestGetControllerClient(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "tmpdir")
if err != nil {
t.Fatalf("error creating temp directory (%s)", err)
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
t.Fatalf("failed to remove builder-key from %s (%s)", tmpDir, err)
}
}()
BuilderKeyLocation = filepath.Join(tmpDir, "builder-key")
data := []byte("testbuilderkey")
if err := os.WriteFile(BuilderKeyLocation, data, 0644); err != nil {
t.Fatalf("error creating %s (%s)", BuilderKeyLocation, err)
}
key, err := GetBuilderKey()
assert.Equal(t, err, nil)
assert.Equal(t, key, string(data), "data")
}
func TestGetBuilderKeyError(t *testing.T) {
_, err := GetBuilderKey()
assert.True(t, err != nil, "no error received when there should have been")
}