carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "context"
5 "fmt"
6 "testing"
7
8 "github.com/carlosframework/platform/internal/release"
9)
10
11// s3ShapedStore wraps Get's errors the way S3Store does.
12type s3ShapedStore struct{ release.Store }
13
14func (s s3ShapedStore) Get(ctx context.Context, key string) ([]byte, string, error) {
15 b, etag, err := s.Store.Get(ctx, key)
16 if err != nil {
17 return nil, "", fmt.Errorf("s3store: %s: %w", key, err)
18 }
19 return b, etag, nil
20}
21
22func TestPutHostReportCreatesThroughAWrappedNotFound(t *testing.T) {
23 ctx := t.Context()
24 store := s3ShapedStore{release.NewDirStore(t.TempDir())}
25 const key = "status/consoles/console-2.json"
26 for _, body := range []string{`{"n":1}`, `{"n":2}`} {
27 if err := putHostReport(ctx, store, key, []byte(body)); err != nil {
28 t.Fatalf("put %s: %v", body, err)
29 }
30 got, _, err := store.Get(ctx, key)
31 if err != nil || string(got) != body {
32 t.Fatalf("stored %q, %v; want %s", got, err, body)
33 }
34 }
35}
36