github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/swarm/api/storage_test.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package api
    13  
    14  import (
    15  	"testing"
    16  )
    17  
    18  func testStorage(t *testing.T, f func(*Storage)) {
    19  	testApi(t, func(api *Api) {
    20  		f(NewStorage(api))
    21  	})
    22  }
    23  
    24  func TestStoragePutGet(t *testing.T) {
    25  	testStorage(t, func(api *Storage) {
    26  		content := "hello"
    27  		exp := expResponse(content, "text/plain", 0)
    28  		// exp := expResponse([]byte(content), "text/plain", 0)
    29  		bzzhash, err := api.Put(content, exp.MimeType)
    30  		if err != nil {
    31  			t.Fatalf("unexpected error: %v", err)
    32  		}
    33  		// to check put against the Api#Get
    34  		resp0 := testGet(t, api.api, bzzhash, "")
    35  		checkResponse(t, resp0, exp)
    36  
    37  		// check storage#Get
    38  		resp, err := api.Get(bzzhash)
    39  		if err != nil {
    40  			t.Fatalf("unexpected error: %v", err)
    41  		}
    42  		checkResponse(t, &testResponse{nil, resp}, exp)
    43  	})
    44  }