Files
kubesphere/pkg/simple/client/s3/fake/fakes3_test.go
runzexia 6a7bf0a86f add s2i controller test
Signed-off-by: runzexia <runzexia@yunify.com>
2020-03-19 09:53:16 +08:00

53 lines
1.0 KiB
Go

package fake
import (
"fmt"
"testing"
)
func TestFakeS3(t *testing.T) {
s3 := NewFakeS3()
key := "hello"
fileName := "world"
err := s3.Upload(key, fileName, nil)
if err != nil {
t.Fatal(err)
}
o, ok := s3.Storage["hello"]
if !ok {
t.Fatal("should have hello object")
}
if o.Key != key || o.FileName != fileName {
t.Fatalf("Key should be %s, FileName should be %s", key, fileName)
}
url, err := s3.GetDownloadURL(key, fileName+"1")
if err != nil {
t.Fatal(err)
}
if url != fmt.Sprintf("http://%s/%s", key, fileName+"1") {
t.Fatalf("url should be %s", fmt.Sprintf("http://%s/%s", key, fileName+"1"))
}
url, err = s3.GetDownloadURL(key, fileName+"2")
if err != nil {
t.Fatal(err)
}
if url != fmt.Sprintf("http://%s/%s", key, fileName+"2") {
t.Fatalf("url should be %s", fmt.Sprintf("http://%s/%s", key, fileName+"2"))
}
err = s3.Delete(key)
if err != nil {
t.Fatal(err)
}
_, ok = s3.Storage["hello"]
if ok {
t.Fatal("should not have hello object")
}
err = s3.Delete(key)
if err != nil {
t.Fatal(err)
}
}