github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/api/storage_test.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 25 package api 26 27 import ( 28 "context" 29 "testing" 30 ) 31 32 func testStorage(t *testing.T, f func(*Storage, bool)) { 33 testAPI(t, func(api *API, toEncrypt bool) { 34 f(NewStorage(api), toEncrypt) 35 }) 36 } 37 38 func TestStoragePutGet(t *testing.T) { 39 testStorage(t, func(api *Storage, toEncrypt bool) { 40 content := "hello" 41 exp := expResponse(content, "text/plain", 0) 42 // 43 ctx := context.TODO() 44 bzzkey, wait, err := api.Put(ctx, content, exp.MimeType, toEncrypt) 45 if err != nil { 46 t.Fatalf("unexpected error: %v", err) 47 } 48 err = wait(ctx) 49 if err != nil { 50 t.Fatalf("unexpected error: %v", err) 51 } 52 bzzhash := bzzkey.Hex() 53 // 54 resp0 := testGet(t, api.api, bzzhash, "") 55 checkResponse(t, resp0, exp) 56 57 // 58 resp, err := api.Get(context.TODO(), bzzhash) 59 if err != nil { 60 t.Fatalf("unexpected error: %v", err) 61 } 62 checkResponse(t, &testResponse{nil, resp}, exp) 63 }) 64 }