Skip to content

Commit c1ede76

Browse files
committed
activation: optionally split test compilation and run phases
1 parent 941053e commit c1ede76

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

activation/common_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 CoreOS, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package activation
16+
17+
import (
18+
"fmt"
19+
"os"
20+
)
21+
22+
// exampleCmd returns the command line for the specified example binary.
23+
func exampleCmd(binaryName string) (string, []string) {
24+
sourcePath := fmt.Sprintf("../examples/activation/%s.go", binaryName)
25+
sourceCmdLine := []string{"go", "run", sourcePath}
26+
binaryPath := fmt.Sprintf("../test_bins/%s.example", binaryName)
27+
if _, err := os.Stat(binaryPath); err != nil && os.IsNotExist(err) {
28+
return sourceCmdLine[0], sourceCmdLine
29+
}
30+
return binaryPath, []string{binaryPath}
31+
}

activation/files_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func correctStringWritten(t *testing.T, r *os.File, expected string) bool {
3838
// TestActivation forks out a copy of activation.go example and reads back two
3939
// strings from the pipes that are passed in.
4040
func TestActivation(t *testing.T) {
41-
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
41+
arg0, cmdline := exampleCmd("activation")
42+
cmd := exec.Command(arg0, cmdline...)
4243

4344
r1, w1, _ := os.Pipe()
4445
r2, w2, _ := os.Pipe()
@@ -60,7 +61,8 @@ func TestActivation(t *testing.T) {
6061
}
6162

6263
func TestActivationNoFix(t *testing.T) {
63-
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
64+
arg0, cmdline := exampleCmd("activation")
65+
cmd := exec.Command(arg0, cmdline...)
6466
cmd.Env = os.Environ()
6567
cmd.Env = append(cmd.Env, "LISTEN_FDS=2")
6668

@@ -71,7 +73,8 @@ func TestActivationNoFix(t *testing.T) {
7173
}
7274

7375
func TestActivationNoFiles(t *testing.T) {
74-
cmd := exec.Command("go", "run", "../examples/activation/activation.go")
76+
arg0, cmdline := exampleCmd("activation")
77+
cmd := exec.Command(arg0, cmdline...)
7578
cmd.Env = os.Environ()
7679
cmd.Env = append(cmd.Env, "LISTEN_FDS=0", "FIX_LISTEN_PID=1")
7780

activation/listeners_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func correctStringWrittenNet(t *testing.T, r net.Conn, expected string) bool {
3838
// TestActivation forks out a copy of activation.go example and reads back two
3939
// strings from the pipes that are passed in.
4040
func TestListeners(t *testing.T) {
41-
cmd := exec.Command("go", "run", "../examples/activation/listen.go")
41+
arg0, cmdline := exampleCmd("listen")
42+
cmd := exec.Command(arg0, cmdline...)
4243

4344
l1, err := net.Listen("tcp", ":9999")
4445
if err != nil {

activation/packetconns_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
// TestActivation forks out a copy of activation.go example and reads back two
2525
// strings from the pipes that are passed in.
2626
func TestPacketConns(t *testing.T) {
27-
cmd := exec.Command("go", "run", "../examples/activation/udpconn.go")
27+
arg0, cmdline := exampleCmd("udpconn")
28+
cmd := exec.Command(arg0, cmdline...)
2829

2930
u1, err := net.ListenUDP("udp", &net.UDPAddr{Port: 9999})
3031
if err != nil {

0 commit comments

Comments
 (0)