GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — workflow/caps_wide_test.go at main · ubgo/workflow

Expand file tree

/

caps_wide_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
132 lines (123 loc) · 5.18 KB
/

caps_wide_test.go

Copy path

File metadata and controls

132 lines (123 loc) · 5.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package workflow_test
import (
"encoding/json"
"errors"
"strings"
"testing"
"github.com/ubgo/workflow"
"github.com/ubgo/workflow/failover"
"github.com/ubgo/workflow/workflowtest"
)
// TestCapsAbove64 proves that a capability numbered past the first 64
// works end to end: a driver declares it, a wrapper keeps or drops it, a
// check finds it missing, and the refusal names it, in every text and
// JSON form. Numbers 191 and the last one (255) sit in the third and
// fourth words, far from the numbers real capabilities take next.
func TestCapsAbove64(t *testing.T) {
high, undoHigh := workflow.DefineCapForTest(191, "Wide191")
t.Cleanup(undoHigh)
top, undoTop := workflow.DefineCapForTest(workflow.CapBitsForTest-1, "Wide255")
t.Cleanup(undoTop)
// Declare: two drivers, one with both wide capabilities.
both := workflowtest.NewFake(workflowtest.FakeCaps(workflow.CapsOf(workflow.CapCron, high, top)))
onlyHigh := workflowtest.NewFake(workflowtest.FakeCaps(workflow.CapsOf(workflow.CapCron, high)))
if got := both.Capabilities(); !got.Has(high) || !got.Has(top) || !got.Has(workflow.CapCron) {
t.Fatalf("declared set = %s, want Cron|Wide191|Wide255", got)
}
if onlyHigh.Capabilities().Has(top) || !onlyHigh.Capabilities().HasAny(workflow.CapsOf(high, top)) {
t.Fatalf("onlyHigh = %s", onlyHigh.Capabilities())
}
// Check through a wrapper: failover declares the intersection.
fo := failover.New(both, onlyHigh).Capabilities()
if !fo.Has(high) || fo.Has(top) {
t.Fatalf("failover over both and onlyHigh = %s, want Wide191 without Wide255", fo)
}
// Refuse: the missing set is exactly the wide capability, and the
// UnsupportedError names it.
need := workflow.CapsOf(workflow.CapCron, high, top)
missing := onlyHigh.Capabilities().Missing(need)
if missing != top {
t.Fatalf("Missing = %s, want Wide255", missing)
}
err := error(&workflow.UnsupportedError{Field: "Wide", Missing: missing, Reason: "test"})
if !errors.Is(err, workflow.ErrUnsupported) || !strings.Contains(err.Error(), "(missing Wide255)") {
t.Fatalf("refusal = %v", err)
}
if !both.Capabilities().Missing(need).IsZero() {
t.Fatalf("both lacks %s", both.Capabilities().Missing(need))
}
// Text and JSON forms round-trip.
set := workflow.CapsOf(workflow.CapDurable, high, top)
if got := set.String(); got != "Durable|Wide191|Wide255" {
t.Fatalf("String = %q", got)
}
parsed, err := workflow.ParseCaps("Durable | Wide191|Wide255")
if err != nil || parsed != set {
t.Fatalf("ParseCaps = %s, %v", parsed, err)
}
b, err := json.Marshal(struct{ Caps workflow.Caps }{set})
if err != nil || string(b) != `{"Caps":"Durable|Wide191|Wide255"}` {
t.Fatalf("json = %s, %v", b, err)
}
var back struct{ Caps workflow.Caps }
if err := json.Unmarshal(b, &back); err != nil || back.Caps != set {
t.Fatalf("json back = %s, %v", back.Caps, err)
}
if got := set.Without(high, workflow.CapDurable); got != top {
t.Fatalf("Without = %s", got)
}
if got := set.Intersect(workflow.CapsOf(top, workflow.CapCron)); got != top {
t.Fatalf("Intersect = %s", got)
}
if !workflow.AllCaps().Has(set) {
t.Fatalf("AllCaps lacks the declared wide capabilities")
}
// A number this release does not declare (a newer release's value)
// prints by number and still round-trips.
undoHigh()
if got := set.String(); got != "Durable|#191|Wide255" {
t.Fatalf("String with an undeclared number = %q", got)
}
if again, err := workflow.ParseCaps(set.String()); err != nil || again != set {
t.Fatalf("ParseCaps(%q) = %s, %v", set.String(), again, err)
}
}
func TestCapsTextAndJSON(t *testing.T) {
if got := (workflow.Caps{}).String(); got != "none" {
t.Fatalf("empty String = %q", got)
}
for _, s := range []string{"", "none", " none "} {
if c, err := workflow.ParseCaps(s); err != nil || !c.IsZero() {
t.Fatalf("ParseCaps(%q) = %s, %v", s, c, err)
}
}
for _, s := range []string{"Durable|Nope", "#-1", "#256", "#x", "Durable||Cron"} {
if _, err := workflow.ParseCaps(s); !errors.Is(err, workflow.ErrInvalid) {
t.Fatalf("ParseCaps(%q) = %v, want ErrInvalid", s, err)
}
}
// The v0.1 numeric form: bit n is capability n.
var c workflow.Caps
if err := json.Unmarshal([]byte("129"), &c); err != nil || c != workflow.CapsOf(workflow.CapDurable, workflow.CapCron) {
t.Fatalf("129 reads as %s, %v; want Durable|Cron", c, err)
}
if err := json.Unmarshal([]byte(`"Cron|DrainReport"`), &c); err != nil || c != workflow.CapsOf(workflow.CapCron, workflow.CapDrainReport) {
t.Fatalf("string reads as %s, %v", c, err)
}
before := c
if err := json.Unmarshal([]byte("null"), &c); err != nil || c != before {
t.Fatalf("null changed %s to %s, %v", before, c, err)
}
for _, bad := range []string{"-1", "1.5", `"Nope"`, "true", "18446744073709551616"} {
if err := json.Unmarshal([]byte(bad), &c); !errors.Is(err, workflow.ErrInvalid) {
t.Fatalf("json %s = %v, want ErrInvalid", bad, err)
}
}
// String lists in number order whatever the build order.
if got := workflow.CapsOf(workflow.CapDrainReport, workflow.CapDurable).String(); got != "Durable|DrainReport" {
t.Fatalf("String order = %q", got)
}
if got := workflow.AllCaps().String(); !strings.HasPrefix(got, "Durable|DelayedStart|") || strings.Contains(got, "#") {
t.Fatalf("AllCaps = %q", got)
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.