Repository navigation
Expand file tree
/
Copy pathscale_test.go
More file actions
62 lines (59 loc) · 1.92 KB
/
Copy pathscale_test.go
File metadata and controls
62 lines (59 loc) · 1.92 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
package main
import (
"context"
"strings"
"testing"
)
func replicaHost(raw string) Host {
h := fakeHost(raw)
old := h.Run
h.Run = func(ctx context.Context, name string, args ...string) ([]byte, error) {
q := name + " " + strings.Join(args, " ")
if strings.Contains(q, "docker ps --filter label=com.docker.compose.project=scale-demo") {
return []byte("abcabcabcabc|worker\ndefdefdefdef|worker\na1a1a1a1a1a1|api\n"), nil
}
if strings.Contains(q, "docker inspect --format") {
return []byte(`{}|||[]`), nil
}
return old(ctx, name, args...)
}
return h
}
func TestScaledServiceDoesNotHideUnrelatedComparison(t *testing.T) {
raw := `{"name":"scale-demo","services":{"api":{"ports":[]},"worker":{"ports":[]}}}`
r, e := inspectLinux(context.Background(), Options{Compare: true}, replicaHost(raw))
if e != nil {
t.Fatal(e)
}
if !hasID(r, "REPLICAS_UNSUPPORTED") {
t.Fatalf("expected explicit replica warning: %+v", r)
}
if hasID(r, "BASELINE_UNKNOWN") {
t.Fatalf("one scaled service must not hide all checks: %+v", r)
}
if hasID(r, "SERVICE_NEW") {
t.Fatalf("scaled worker is not a new service: %+v", r)
}
if hasID(r, "RUNNING_MATCH") {
t.Fatalf("partial result must not claim complete match: %+v", r)
}
}
func TestOnlyScaledServiceDoesNotClaimMissingStack(t *testing.T) {
raw := `{"name":"scale-demo","services":{"worker":{"ports":[]}}}`
h := replicaHost(raw)
old := h.Run
h.Run = func(ctx context.Context, name string, args ...string) ([]byte, error) {
q := name + " " + strings.Join(args, " ")
if strings.Contains(q, "docker ps --filter label=com.docker.compose.project=scale-demo") {
return []byte("abcabcabcabc|worker\ndefdefdefdef|worker\n"), nil
}
return old(ctx, name, args...)
}
r, e := inspectLinux(context.Background(), Options{Compare: true}, h)
if e != nil {
t.Fatal(e)
}
if !hasID(r, "REPLICAS_UNSUPPORTED") || hasID(r, "NO_RUNNING_STACK") {
t.Fatalf("replicas are running: %+v", r)
}
}