forked from kata-containers/shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
46 lines (38 loc) · 780 Bytes
/
main_test.go
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
// Copyright 2018 Intel Corporation.
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"bytes"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInitLogger(t *testing.T) {
origStdout := os.Stdout
origStderr := os.Stderr
r, w, err := os.Pipe()
assert.Nil(t, err, "Could not create the pipe: %v", err)
os.Stdout = w
os.Stderr = w
defer func() {
r.Close()
w.Close()
os.Stdout = origStdout
os.Stderr = origStderr
}()
testOutString := "Foo Bar"
initLogger("debug", "container-id", "exec-id")
logger().Info(testOutString)
outC := make(chan string)
go func() {
var buf bytes.Buffer
io.Copy(&buf, r)
outC <- buf.String()
}()
w.Close()
out := <-outC
assert.Equal(t, out, "", "Expecting %q to be empty", out)
}