@@ -3,7 +3,6 @@ package conf
33import (
44 "io/ioutil"
55 "os"
6- "os/user"
76 "path/filepath"
87 "testing"
98
@@ -12,73 +11,26 @@ import (
1211)
1312
1413func TestGetStorageParams (t * testing.T ) {
15- usr , err := user .Current ()
16- if err != nil {
17- t .Logf ("could not retrieve current user: %v" , err )
18- t .SkipNow ()
19- }
20- if usr .Uid != "0" {
21- t .Logf ("current user does not have UID of zero (got %s) " +
22- "so cannot create storage cred location, skipping" , usr .Uid )
23- t .SkipNow ()
24- }
25-
26- if err := os .MkdirAll (storageCredLocation , os .ModeDir ); err != nil {
27- t .Fatalf ("could not create storage cred location: %v" , err )
28- }
29-
30- // start by writing out a file to storageCredLocation
31- data := []byte ("hello world\n " )
32- if err := ioutil .WriteFile (storageCredLocation + "foo" , data , 0644 ); err != nil {
33- t .Fatalf ("could not write file to storage cred location: %v" , err )
34- }
35-
36- params , err := GetStorageParams (sys .NewFakeEnv ())
37- if err != nil {
38- t .Errorf ("received error while retrieving storage params: %v" , err )
39- }
40-
41- val , ok := params ["foo" ]
42- if ! ok {
43- t .Error ("key foo does not exist in storage params" )
44- }
45- if val != string (data ) {
46- t .Errorf ("expected: %s got: %s" , string (data ), val )
47- }
48-
49- // create a directory inside storage cred location, expecting it to pass
50- if err := os .Mkdir (storageCredLocation + "bar" , os .ModeDir ); err != nil {
51- t .Fatalf ("could not create dir %s: %v" , storageCredLocation + "bar" , err )
52- }
53-
54- _ , err = GetStorageParams (sys .NewFakeEnv ())
55- if err != nil {
56- t .Errorf ("received error while retrieving storage params: %v" , err )
57- }
58-
59- // create the special "..data" directory symlink, expecting it to pass
60- if err := os .Symlink (storageCredLocation + "bar" , storageCredLocation + "..data" ); err != nil {
61- t .Fatalf ("could not create dir symlink ..data -> %s: %v" , storageCredLocation + "bar" , err )
62- }
63-
64- _ , err = GetStorageParams (sys .NewFakeEnv ())
65- if err != nil {
66- t .Errorf ("received error while retrieving storage params: %v" , err )
67- }
6814
6915 env := sys .NewFakeEnv ()
7016 env .Envs = map [string ]string {
71- "BUILDER_STORAGE" : "minio" ,
72- "DRYCC_MINIO_ENDPOINT" : "http://localhost:8088" ,
73- }
74- params , err = GetStorageParams (env )
17+ "BUILDER_STORAGE" : "minio" ,
18+ "DRYCC_MINIO_LOOKUP" : "path" ,
19+ "DRYCC_MINIO_BUCKET" : "builder" ,
20+ "DRYCC_MINIO_ENDPOINT" : "http://localhost:8088" ,
21+ "DRYCC_MINIO_ACCESSKEY" : "admin" ,
22+ "DRYCC_MINIO_SECRETKEY" : "adminpass" ,
23+ }
24+ params , err := GetStorageParams (env )
7525 if err != nil {
7626 t .Errorf ("received error while retrieving storage params: %v" , err )
7727 }
28+ assert .Equal (t , params ["forcepathstyle" ], "true" , "forcepathstyle" )
7829 assert .Equal (t , params ["regionendpoint" ], "http://localhost:8088" , "region endpoint" )
79- assert .Equal (t , params ["secure" ], false , "secure" )
80- assert .Equal (t , params ["region" ], "us-east-1" , "region" )
30+ assert .Equal (t , params ["region" ], "localhost" , "region" )
8131 assert .Equal (t , params ["bucket" ], "builder" , "bucket" )
32+ assert .Equal (t , params ["accesskey" ], "admin" , "accesskey" )
33+ assert .Equal (t , params ["secretkey" ], "adminpass" , "secretkey" )
8234}
8335
8436func TestGetControllerClient (t * testing.T ) {
0 commit comments