carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package archive
2
3import (
4 "bytes"
5 "os"
6 "path/filepath"
7 "testing"
8)
9
10// The move archive carries <host>.env byte for byte, so the instance key
11// lands on the target exactly as the source minted it (L21: the key is the
12// exact bytes the env file yields).
13func TestArchiveCarriesTheInstanceKeyByteForByte(t *testing.T) {
14 dir, env := filesFixture(t)
15 body := []byte("CARLOS_ADMIN_TOKEN=t\nCARLOS_INSTANCE_KEY=q+/Zk3vJ0aW1Yx9sR7tUe2oPl4mN8bC6dF5gH0iJ1kA=\n")
16 mustWrite(t, env, body, 0o600)
17 var built bytes.Buffer
18 if _, _, _, err := Build(dir, env, &built); err != nil {
19 t.Fatal(err)
20 }
21 out := filepath.Join(t.TempDir(), "out")
22 outEnv := filepath.Join(t.TempDir(), "out.env")
23 if err := Extract(bytes.NewReader(built.Bytes()), out, outEnv); err != nil {
24 t.Fatal(err)
25 }
26 got, err := os.ReadFile(outEnv)
27 if err != nil || !bytes.Equal(got, body) {
28 t.Fatalf("extracted env differs from the source's: %d bytes, want %d (err %v)", len(got), len(body), err)
29 }
30}
31