-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathordering_test.go
More file actions
129 lines (116 loc) · 3.31 KB
/
Copy pathordering_test.go
File metadata and controls
129 lines (116 loc) · 3.31 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
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
// Copyright 2026 HAProxy Technologies LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package e2e
import (
"strings"
"testing"
"time"
)
func TestBeforeOrdering(t *testing.T) {
dir, code, out := runContainer(t, map[string]string{
"gopherd.yml": `
no-logo: true
processes:
- name: first
command: /bin/sh
args: ["-c", "echo first >> /test/order.log && sleep 300"]
before: [second]
on-failure: shutdown
- name: second
command: /bin/sh
args: ["-c", "echo second >> /test/order.log && sleep 1"]
on-success: success-shutdown
on-failure: failure-shutdown
`,
}, 15*time.Second)
if code != 0 {
t.Fatalf("exit %d\noutput:\n%s", code, out)
}
data := readTestFile(t, dir, "order.log")
lines := strings.Split(strings.TrimSpace(data), "\n")
if len(lines) < 2 {
t.Fatalf("expected 2 lines, got %d: %q", len(lines), data)
}
if lines[0] != "first" || lines[1] != "second" {
t.Errorf("expected [first, second], got %v", lines)
}
}
func TestAfterOrdering(t *testing.T) {
// Use oneshot for "first" so it completes before "second" starts,
// guaranteeing deterministic write order.
dir, code, out := runContainer(t, map[string]string{
"gopherd.yml": `
no-logo: true
processes:
- name: first
command: /bin/sh
args: ["-c", "echo first >> /test/order.log"]
startup: oneshot
- name: second
command: /bin/sh
args: ["-c", "echo second >> /test/order.log && sleep 1"]
after: [first]
on-success: success-shutdown
on-failure: failure-shutdown
`,
}, 15*time.Second)
if code != 0 {
t.Fatalf("exit %d\noutput:\n%s", code, out)
}
data := readTestFile(t, dir, "order.log")
lines := strings.Split(strings.TrimSpace(data), "\n")
if len(lines) < 2 {
t.Fatalf("expected 2 lines, got %d: %q", len(lines), data)
}
if lines[0] != "first" || lines[1] != "second" {
t.Errorf("expected [first, second], got %v", lines)
}
}
func TestRequiresCascade(t *testing.T) {
_, code, out := runContainer(t, map[string]string{
"gopherd.yml": `
no-logo: true
export-socket: true
processes:
- name: db
command: /bin/sh
args: ["-c", "sleep 1 && exit 1"]
on-failure: ignore
- name: app
command: /bin/sh
args: ["-c", "sleep 300"]
requires: [db]
on-success: ignore
on-failure: ignore
- name: test-runner
command: /test/assert.sh
on-success: success-shutdown
on-failure: failure-shutdown
`,
"assert.sh": `#!/bin/sh
# Wait for db to crash and cascade to stop app.
sleep 4
status=$(/usr/local/bin/gopherd app status 2>&1)
echo "app status: $status"
echo "$status" | grep -q "stopped" || { echo "FAIL: app should be stopped"; exit 1; }
echo "PASS: requires cascade worked"
`,
}, 15*time.Second)
if code != 0 {
t.Fatalf("exit %d\noutput:\n%s", code, out)
}
if !strings.Contains(out, "PASS") {
t.Errorf("requires cascade check inconclusive:\n%s", out)
}
}