Skip to content

Commit 7e481ee

Browse files
committed
libct/int: remove logger from init
Currently, TestInit sets up logrus, and init uses it to log an error from StartInitialization(). This is solely used by TestExecInError to check that error returned from StartInitialization is the one it expects. Note that the very same error is communicated to the runc init parent and is ultimately returned by container.Run(), so checking what StartInitialization returned is redundant. Remove logrus setup and use from TestMain/init. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent eba31a7 commit 7e481ee

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

libcontainer/integration/execin_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,10 @@ func TestExecInError(t *testing.T) {
215215
ok(t, err)
216216

217217
for i := 0; i < 42; i++ {
218-
var out bytes.Buffer
219218
unexistent := &libcontainer.Process{
220-
Cwd: "/",
221-
Args: []string{"unexistent"},
222-
Env: standardEnvironment,
223-
Stderr: &out,
219+
Cwd: "/",
220+
Args: []string{"unexistent"},
221+
Env: standardEnvironment,
224222
}
225223
err = container.Run(unexistent)
226224
if err == nil {
@@ -229,9 +227,6 @@ func TestExecInError(t *testing.T) {
229227
if !strings.Contains(err.Error(), "executable file not found") {
230228
t.Fatalf("Should be error about not found executable, got %s", err)
231229
}
232-
if !bytes.Contains(out.Bytes(), []byte("executable file not found")) {
233-
t.Fatalf("executable file not found error not delivered to stdio:\n%s", out.String())
234-
}
235230
}
236231
}
237232

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package integration
22

33
import (
4+
"fmt"
45
"os"
56
"runtime"
67
"testing"
@@ -9,27 +10,27 @@ import (
910
//nolint:revive // Enable cgroup manager to manage devices
1011
_ "github.com/opencontainers/runc/libcontainer/cgroups/devices"
1112
_ "github.com/opencontainers/runc/libcontainer/nsenter"
12-
13-
"github.com/sirupsen/logrus"
1413
)
1514

16-
// init runs the libcontainer initialization code because of the busybox style needs
17-
// to work around the go runtime and the issues with forking
15+
// Same as ../../init.go but for libcontainer/integration.
1816
func init() {
1917
if len(os.Args) < 2 || os.Args[1] != "init" {
2018
return
2119
}
20+
// This is the golang entry point for runc init, executed
21+
// before TestMain() but after libcontainer/nsenter's nsexec().
2222
runtime.GOMAXPROCS(1)
2323
runtime.LockOSThread()
2424
if err := libcontainer.StartInitialization(); err != nil {
25-
logrus.Fatal(err)
25+
// logrus is not initialized
26+
fmt.Fprintln(os.Stderr, err)
2627
}
28+
// Normally, StartInitialization() never returns, meaning
29+
// if we are here, it had failed.
30+
os.Exit(1)
2731
}
2832

2933
func TestMain(m *testing.M) {
30-
logrus.SetOutput(os.Stderr)
31-
logrus.SetLevel(logrus.InfoLevel)
32-
3334
ret := m.Run()
3435
os.Exit(ret)
3536
}

0 commit comments

Comments
 (0)