-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadiness_test.go
More file actions
68 lines (60 loc) · 2.17 KB
/
Copy pathreadiness_test.go
File metadata and controls
68 lines (60 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package starmap
import (
"testing"
"time"
"github.com/agentstation/starmap/internal/embeddedbudget"
)
func TestEmbeddedBudgetReadinessReportsGenerationAgeVersionAndSize(t *testing.T) {
client, err := New(
WithEmbeddedBootstrapMaxAge(24*time.Hour),
WithEmbeddedBootstrapMaxSizeBytes(embeddedbudget.DefaultMaxUncompressedBytes),
)
if err != nil {
t.Fatalf("New offline bootstrap: %v", err)
}
generatedAt := client.embeddedBootstrap.GeneratedAt
client.now = func() time.Time { return generatedAt.Add(12 * time.Hour) }
readiness := client.Readiness()
if !readiness.Ready || len(readiness.Issues) != 0 {
t.Fatalf("readiness = %#v", readiness)
}
info := readiness.Embedded
if !info.Active || info.GenerationID == "" || info.ManifestVersion == 0 ||
info.SchemaVersion == 0 || info.PayloadChecksum == "" || info.PayloadSizeBytes <= 0 ||
info.AgeSeconds != int64((12*time.Hour)/time.Second) {
t.Fatalf("embedded bootstrap info = %#v", info)
}
}
func TestEmbeddedBudgetReadinessFailsClosedForStaleAndOversizeBootstrap(t *testing.T) {
client, err := New(
WithEmbeddedBootstrapMaxAge(time.Hour),
WithEmbeddedBootstrapMaxSizeBytes(1),
)
if err != nil {
t.Fatalf("New: %v", err)
}
client.now = func() time.Time { return client.embeddedBootstrap.GeneratedAt.Add(2 * time.Hour) }
readiness := client.Readiness()
if readiness.Ready || len(readiness.Issues) != 2 {
t.Fatalf("readiness = %#v, want stale and oversize", readiness)
}
if readiness.Issues[0].Code != ReadinessIssueEmbeddedBootstrapStale ||
readiness.Issues[1].Code != ReadinessIssueEmbeddedBootstrapOversize {
t.Fatalf("readiness issue codes = %#v", readiness.Issues)
}
client.swapCatalogGeneration(client.Catalog(), "published-generation")
readiness = client.Readiness()
if !readiness.Ready || readiness.Embedded.Active {
t.Fatalf("published generation should supersede bootstrap budgets: %#v", readiness)
}
}
func TestEmbeddedBudgetOptionsRejectNonPositiveValues(t *testing.T) {
for _, option := range []Option{
WithEmbeddedBootstrapMaxAge(0),
WithEmbeddedBootstrapMaxSizeBytes(0),
} {
if _, err := New(option); err == nil {
t.Fatal("New accepted a non-positive embedded bootstrap budget")
}
}
}