carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package hostops
2
3import (
4 "context"
5 "errors"
6 "testing"
7
8 "github.com/carlosframework/platform/internal/release"
9)
10
11// TestClassifyPointerDigestMarkerIsExact: the account's pointer digest marker
12// (#253) is a reviewed non-app family, put and deleted; nothing else under
13// releases/ is.
14func TestClassifyPointerDigestMarkerIsExact(t *testing.T) {
15 ctx := context.Background()
16 key := release.PointerDigestsKey("bab")
17 for _, c := range []struct {
18 name string
19 target MutationTarget
20 }{
21 {"marker put", MutationTarget{Surface: "bucket", Method: "Put", Key: key, After: []byte(`{}`)}},
22 {"marker put over an existing one", MutationTarget{Surface: "bucket", Method: "Put", Key: key, ETag: "x", Before: []byte(`{}`), After: []byte(`{}`)}},
23 {"marker delete", MutationTarget{Surface: "bucket", Method: "Delete", Key: key}},
24 } {
25 got, err := ClassifyMutation(ctx, nil, nil, c.target)
26 if err != nil {
27 t.Errorf("%s: %v", c.name, err)
28 continue
29 }
30 if got.Family != "pointer-digest-marker" || got.NonApp == "" || len(got.Scopes) != 0 || got.MailGate {
31 t.Errorf("%s: classified %+v, want non-app family pointer-digest-marker with no scopes", c.name, got)
32 }
33 }
34 for _, c := range []struct {
35 name string
36 target MutationTarget
37 }{
38 {"an invalid account", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/BAB!/pointer-digests", After: []byte(`{}`)}},
39 {"an empty account", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases//pointer-digests", After: []byte(`{}`)}},
40 {"a fourth segment", MutationTarget{Surface: "bucket", Method: "Put", Key: key + "/x", After: []byte(`{}`)}},
41 {"another name under the account", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/bab/other", After: []byte(`{}`)}},
42 {"a lookalike name", MutationTarget{Surface: "bucket", Method: "Put", Key: key + ".json", After: []byte(`{}`)}},
43 {"the account prefix itself", MutationTarget{Surface: "bucket", Method: "Delete", Key: "releases/bab"}},
44 {"a delete-if-match", MutationTarget{Surface: "bucket", Method: "DeleteIfMatch", Key: key, ETag: "x"}},
45 } {
46 if got, err := ClassifyMutation(ctx, nil, nil, c.target); !errors.Is(err, ErrUnclassified) {
47 t.Errorf("%s: classified %+v, err %v; want ErrUnclassified", c.name, got, err)
48 }
49 }
50}
51