github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/swarm/api/storage_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:47</date> 10 //</624342670164103168> 11 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 // 25 // 26 // 27 28 package api 29 30 import ( 31 "context" 32 "testing" 33 ) 34 35 func testStorage(t *testing.T, f func(*Storage, bool)) { 36 testAPI(t, func(api *API, toEncrypt bool) { 37 f(NewStorage(api), toEncrypt) 38 }) 39 } 40 41 func TestStoragePutGet(t *testing.T) { 42 testStorage(t, func(api *Storage, toEncrypt bool) { 43 content := "hello" 44 exp := expResponse(content, "text/plain", 0) 45 // 46 ctx := context.TODO() 47 bzzkey, wait, err := api.Put(ctx, content, exp.MimeType, toEncrypt) 48 if err != nil { 49 t.Fatalf("unexpected error: %v", err) 50 } 51 err = wait(ctx) 52 if err != nil { 53 t.Fatalf("unexpected error: %v", err) 54 } 55 bzzhash := bzzkey.Hex() 56 // 57 resp0 := testGet(t, api.api, bzzhash, "") 58 checkResponse(t, resp0, exp) 59 60 // 61 resp, err := api.Get(context.TODO(), bzzhash) 62 if err != nil { 63 t.Fatalf("unexpected error: %v", err) 64 } 65 checkResponse(t, &testResponse{nil, resp}, exp) 66 }) 67 } 68