carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package release
2
3import (
4 "bytes"
5 "context"
6 "os"
7 "testing"
8)
9
10func TestGetManifestRawReturnsTheBytesItParsed(t *testing.T) {
11 s := NewDirStore(t.TempDir())
12 raw := putRawRelease(t, s, "bab", "km", "v1", []byte("bin"), `"swap":"hold","from_a_newer_shipper":{"x":1},`)
13 m, got, err := GetManifestRaw(context.Background(), s, "bab", "km", "v1")
14 if err != nil {
15 t.Fatalf("GetManifestRaw: %v", err)
16 }
17 if !bytes.Equal(got, raw) || m.Swap != DemandHold {
18 t.Fatalf("GetManifestRaw = %+v, %s; want the stored bytes and swap hold", m, got)
19 }
20}
21
22// Spec §4.2: copies staged from now on are lossless. A field this binary does
23// not know survives in the sibling.
24func TestStagedSiblingKeepsTheCanonicalBytes(t *testing.T) {
25 s := NewDirStore(t.TempDir())
26 ctx := context.Background()
27 opt := t.TempDir()
28 raw := putRawRelease(t, s, "bab", "km", "v1", []byte("bin"), `"swap":"hold","from_a_newer_shipper":{"x":1},`)
29 if _, err := ensureStaged(ctx, s, opt, "bab", "km", "v1", "h.example.com"); err != nil {
30 t.Fatalf("ensureStaged: %v", err)
31 }
32 got, err := os.ReadFile(StagedManifestPath(opt, "bab", "v1", "km"))
33 if err != nil {
34 t.Fatal(err)
35 }
36 if !bytes.Equal(got, raw) {
37 t.Fatalf("staged sibling is not the canonical bytes:\n got %s\nwant %s", got, raw)
38 }
39 m, err := ReadStagedManifest(opt, "bab", "v1", "km")
40 if err != nil || m == nil || m.Swap != DemandHold {
41 t.Fatalf("ReadStagedManifest = %+v, %v; want the canonical manifest back", m, err)
42 }
43}
44
45func TestBackfilledSiblingKeepsTheCanonicalBytes(t *testing.T) {
46 s := NewDirStore(t.TempDir())
47 ctx := context.Background()
48 opt := t.TempDir()
49 raw := putRawRelease(t, s, "bab", "km", "v1", []byte("bin"), `"from_a_newer_shipper":true,`)
50 if err := StageArtifact(opt, "bab", "v1", "km", []byte("bin")); err != nil {
51 t.Fatal(err)
52 }
53 backfillManifest(ctx, s, opt, "bab", "km", "v1", "h.example.com")
54 got, err := os.ReadFile(StagedManifestPath(opt, "bab", "v1", "km"))
55 if err != nil || !bytes.Equal(got, raw) {
56 t.Fatalf("back-filled sibling = %s, %v; want the canonical bytes %s", got, err, raw)
57 }
58}
59