github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/s3/mem_test.go (about)

     1  package s3
     2  
     3  import (
     4  	"bytes"
     5  	"crypto/sha256"
     6  	"github.com/keybase/client/go/libkb"
     7  	"strings"
     8  	"testing"
     9  
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  type ptsign struct{}
    14  
    15  func (p *ptsign) Sign(payload []byte) ([]byte, error) {
    16  	s := sha256.Sum256(payload)
    17  	return s[:], nil
    18  }
    19  
    20  func TestMemPut(t *testing.T) {
    21  	tc := libkb.SetupTest(t, "team", 1)
    22  	defer tc.Cleanup()
    23  
    24  	m := &Mem{}
    25  	c := m.New(tc.G, &ptsign{}, Region{})
    26  	b := c.Bucket("bucket-1")
    27  	path := "abc/def"
    28  	content := "bucket content"
    29  	if err := b.PutReader(context.TODO(), path, strings.NewReader(content), int64(len(content)), "string", Private, Options{}); err != nil {
    30  		t.Fatal(err)
    31  	}
    32  	r, err := b.GetReader(context.TODO(), path)
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  	var buf bytes.Buffer
    37  	n, err := buf.ReadFrom(r)
    38  	if err != nil {
    39  		t.Fatal(err)
    40  	}
    41  	if n != int64(len(content)) {
    42  		t.Errorf("length: %d, expected %d", n, len(content))
    43  	}
    44  	s := buf.String()
    45  	if s != content {
    46  		t.Errorf("read data: %q, expected %q", s, content)
    47  	}
    48  }