fakes3_test.go 1.0 KB
Newer Older
R
runzexia 已提交
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
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)
	}
}