2
Copyright 2013 CoreOS Inc.
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
8
http://www.apache.org/licenses/LICENSE-2.0
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
27
// correctStringWritten fails the text if the correct string wasn't written
28
// to the other side of the pipe.
29
func correctStringWritten(t *testing.T, r *os.File, expected string) bool {
30
bytes := make([]byte, len(expected))
31
io.ReadAtLeast(r, bytes, len(expected))
33
if string(bytes) != expected {
34
t.Fatalf("Unexpected string %s", string(bytes))
40
// TestActivation forks out a copy of activation.go example and reads back two
41
// strings from the pipes that are passed in.
42
func TestActivation(t *testing.T) {
43
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
45
r1, w1, _ := os.Pipe()
46
r2, w2, _ := os.Pipe()
47
cmd.ExtraFiles = []*os.File{
52
cmd.Env = os.Environ()
53
cmd.Env = append(cmd.Env, "LISTEN_FDS=2", "FIX_LISTEN_PID=1")
60
correctStringWritten(t, r1, "Hello world")
61
correctStringWritten(t, r2, "Goodbye world")
64
func TestActivationNoFix(t *testing.T) {
65
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
66
cmd.Env = os.Environ()
67
cmd.Env = append(cmd.Env, "LISTEN_FDS=2")
69
out, _ := cmd.CombinedOutput()
70
if bytes.Contains(out, []byte("No files")) == false {
71
t.Fatalf("Child didn't error out as expected")
75
func TestActivationNoFiles(t *testing.T) {
76
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
77
cmd.Env = os.Environ()
78
cmd.Env = append(cmd.Env, "LISTEN_FDS=0", "FIX_LISTEN_PID=1")
80
out, _ := cmd.CombinedOutput()
81
if bytes.Contains(out, []byte("No files")) == false {
82
t.Fatalf("Child didn't error out as expected")