-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efd1b75
commit 7c72172
Showing
3 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package storage | ||
|
||
import "strings" | ||
|
||
type Minio struct { | ||
Storage | ||
} | ||
|
||
func (m *Minio) Type() string { | ||
return string(MinioType) | ||
} | ||
|
||
func (m *Minio) PodEnvVars() map[string]string { | ||
s3 := m.Storage.(*S3) | ||
endpoint := strings.Split(trimEndpoint(s3.Endpoint), ":") | ||
return map[string]string{ | ||
"S3_HOST": endpoint[0], | ||
"S3_PORT": endpoint[1], | ||
"MINIO_BUCKET": s3.Bucket, | ||
} | ||
} | ||
|
||
func trimEndpoint(endpoint string) string { | ||
for _, s := range []string{"http://", "https://"} { | ||
endpoint = strings.TrimPrefix(endpoint, s) | ||
} | ||
return endpoint | ||
} | ||
|
||
func newMinio(conf *Config) Storage { | ||
s3 := newS3(conf) | ||
return &Minio{Storage: s3} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package storage | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestMinioType(t *testing.T) { | ||
minio := newMinio(&Config{}) | ||
if tmp := minio.Type(); tmp != "minio" { | ||
t.Errorf("expected minio, got %s", tmp) | ||
} | ||
} | ||
|
||
func TestMinioPodEnvVars(t *testing.T) { | ||
expectedHost := "url" | ||
expectedPort := "9000" | ||
expectedBucket := "test" | ||
minio := newMinio(&Config{ | ||
AwsEndpoint: fmt.Sprintf("http://%s:%s", expectedHost, expectedPort), | ||
AwsBucket: expectedBucket, | ||
}) | ||
ev := minio.PodEnvVars() | ||
|
||
var testCases = []struct { | ||
env string | ||
expected string | ||
}{ | ||
{"S3_HOST", expectedHost}, | ||
{"S3_PORT", expectedPort}, | ||
{"MINIO_BUCKET", expectedBucket}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
if tmp := ev[tc.env]; tmp != tc.expected { | ||
t.Errorf("expected %s, got %s", tc.expected, tc.env) | ||
} | ||
} | ||
} | ||
|
||
func TestTrimEndpoint(t *testing.T) { | ||
var testCases = []struct { | ||
input string | ||
expected string | ||
}{ | ||
{"http://foo.com", "foo.com"}, | ||
{"https://teresa.io", "teresa.io"}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
if actual := trimEndpoint(tc.input); actual != tc.expected { | ||
t.Errorf("expected %s, got %s", tc.expected, actual) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters