Repository navigation
Expand file tree
/
Copy pathmain_test.go
More file actions
71 lines (66 loc) · 2.16 KB
/
Copy pathmain_test.go
File metadata and controls
71 lines (66 loc) · 2.16 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
package main
import (
"slices"
"testing"
)
func TestParseCapabilities(t *testing.T) {
got, err := parseCapabilities("strict_conformance, oslc_query")
if err != nil {
t.Fatalf("parseCapabilities: %v", err)
}
want := []string{"strict_conformance", "oslc_query"}
if !slices.Equal(got, want) {
t.Errorf("capabilities = %v, want %v", got, want)
}
if _, err := parseCapabilities("query,query"); err == nil {
t.Error("duplicate capability was accepted")
}
}
func TestValidateWithheldCapabilities(t *testing.T) {
defaults := []string{"oslc_query", "query", "strict_conformance"}
actual := []string{"query"}
if err := validateWithheldCapabilities(defaults, actual,
[]string{"oslc_query", "strict_conformance"}); err != nil {
t.Errorf("valid withheld set: %v", err)
}
if err := validateWithheldCapabilities(defaults, defaults,
[]string{"strict_conformance"}); err == nil {
t.Error("service that retained a withheld capability was accepted")
}
if err := validateWithheldCapabilities(defaults, defaults,
[]string{"unknown"}); err == nil {
t.Error("capability absent from the default service was accepted")
}
}
func TestValidateFallbackExecution(t *testing.T) {
summary := &Summary{Results: []*Result{
{
ID: "strict",
Outcome: "pass",
WithoutCapability: true,
MissingCapabilities: []string{"strict_conformance"},
},
{
ID: "oslc",
Outcome: "pass",
WithoutCapability: true,
MissingCapabilities: []string{"oslc_query"},
},
{
ID: "skipped",
Outcome: "skip",
MissingCapabilities: []string{"oslc_query"},
},
}}
unavailable := []string{"strict_conformance", "oslc_query"}
if err := validateFallbackExecution(summary, unavailable, false); err != nil {
t.Errorf("executed fallbacks: %v", err)
}
if err := validateFallbackExecution(summary, append(unavailable, "query"), false); err == nil {
t.Error("unexecuted fallback was accepted")
}
summary.Results[2].MissingCapabilities = []string{"verification"}
if err := validateFallbackExecution(summary, unavailable, false); err == nil {
t.Error("unexpected missing capability was accepted")
}
}