minipaste/store/store_test.go
2022-04-20 02:37:27 +02:00

46 lines
821 B
Go

package store_test
import (
"io"
"strings"
"testing"
"git.t-juice.club/torjus/minipaste/store"
)
func testStore(s store.Store, t *testing.T) {
t.Run("TestSimple", func(t *testing.T) {
expected := "this is some text"
sr := strings.NewReader(expected)
// Add
id, err := s.Add(sr)
if err != nil {
t.Fatalf("Error when adding: %s", err)
}
if id == "" {
t.Fatalf("Blank ID returned")
}
// Get
data, err := s.Get(id)
if err != nil {
t.Fatalf("Error getting data: %s", err)
}
var sb strings.Builder
if _, err := io.Copy(&sb, data); err != nil {
t.Fatalf("Error reading returned data: %s", err)
}
if sb.String() != expected {
t.Fatalf("Returned data does not match expected")
}
if err := s.Delete(id); err != nil {
t.Fatalf("Error deleting: %s", err)
}
})
}