Repository navigation
Expand file tree
/
Copy pathfeature_report_test.go
More file actions
85 lines (79 loc) · 2.63 KB
/
Copy pathfeature_report_test.go
File metadata and controls
85 lines (79 loc) · 2.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gatekit
import (
"strings"
"testing"
)
func TestDescriptionGetter(t *testing.T) {
g, err := New(testRegistry(), StaticVersion(6))
if err != nil {
t.Fatalf("New() error: %v", err)
}
if got := g.Description(featureA); got != "feature A" {
t.Errorf("Description(featureA) = %q, want %q", got, "feature A")
}
if got := g.Description(featureB); got != "" {
t.Errorf("Description(featureB) = %q, want empty", got)
}
if got := g.Description("unknown"); got != "" {
t.Errorf("Description(unknown) = %q, want empty", got)
}
}
func TestDescriptionDoesNotAffectResolution(t *testing.T) {
withDesc := Registry{
featureA: {Description: "has a description", Specs: VersionedSpecs{{ActiveFrom: 4, Default: true, Maturity: GA}}},
}
noDesc := Registry{
featureA: {Specs: VersionedSpecs{{ActiveFrom: 4, Default: true, Maturity: GA}}},
}
g1, _ := New(withDesc, StaticVersion(5))
g2, _ := New(noDesc, StaticVersion(5))
if g1.Enabled(featureA) != g2.Enabled(featureA) {
t.Errorf("description changed resolution: with=%v without=%v",
g1.Enabled(featureA), g2.Enabled(featureA))
}
if g1.EffectiveVersion() != g2.EffectiveVersion() {
t.Errorf("description changed EffectiveVersion: with=%+v without=%+v",
g1.EffectiveVersion(), g2.EffectiveVersion())
}
}
func TestReport(t *testing.T) {
g, err := New(testRegistry(), StaticVersion(6))
if err != nil {
t.Fatalf("New() error: %v", err)
}
rep := g.Report()
if rep.Version != 6 {
t.Errorf("Report().Version = %d, want 6", rep.Version)
}
if len(rep.Features) != 2 {
t.Fatalf("Report() has %d features, want 2", len(rep.Features))
}
// Sorted by feature identifier: featureA, featureB.
a := rep.Features[0]
if a.Feature != featureA || a.Description != "feature A" || !a.Enabled || a.Maturity != GA {
t.Errorf("featureA info = %+v, want {featureA, desc, enabled, GA}", a)
}
b := rep.Features[1]
if b.Feature != featureB || b.Enabled || b.Maturity != Alpha {
t.Errorf("featureB info = %+v, want {featureB, off, ALPHA}", b)
}
text := rep.String()
for _, want := range []string{"Features at activation 6:", "featureA", "[GA] on", "feature A", "featureB", "[ALPHA] off"} {
if !strings.Contains(text, want) {
t.Errorf("report text missing %q:\n%s", want, text)
}
}
}
func TestReportAtUnreachedFeature(t *testing.T) {
g, err := New(testRegistry(), StaticVersion(0))
if err != nil {
t.Fatalf("New() error: %v", err)
}
rep := g.ReportAt(3) // before featureA's first spec (v4)
if rep.Features[0].Maturity != "" {
t.Errorf("unreached feature Maturity = %q, want empty", rep.Features[0].Maturity)
}
if rep.Features[0].Enabled {
t.Errorf("unreached feature should be off")
}
}