|
@@ -1,12 +1,16 @@
|
|
|
package container // import "github.com/docker/docker/container"
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+ "io/ioutil"
|
|
|
"path/filepath"
|
|
|
"testing"
|
|
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
|
|
+ "github.com/docker/docker/daemon/logger/jsonfilelog"
|
|
|
"github.com/docker/docker/pkg/signal"
|
|
|
+ "github.com/stretchr/testify/require"
|
|
|
)
|
|
|
|
|
|
func TestContainerStopSignal(t *testing.T) {
|
|
@@ -66,3 +70,52 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) {
|
|
|
t.Fatalf("expected secret dest %q; received %q", expected, d)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestContainerLogPathSetForJSONFileLogger(t *testing.T) {
|
|
|
+ containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForJSONFileLogger")
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ c := &Container{
|
|
|
+ Config: &container.Config{},
|
|
|
+ HostConfig: &container.HostConfig{
|
|
|
+ LogConfig: container.LogConfig{
|
|
|
+ Type: jsonfilelog.Name,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ID: "TestContainerLogPathSetForJSONFileLogger",
|
|
|
+ Root: containerRoot,
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = c.StartLogger()
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID)))
|
|
|
+ require.NoError(t, err)
|
|
|
+ require.Equal(t, c.LogPath, expectedLogPath)
|
|
|
+}
|
|
|
+
|
|
|
+func TestContainerLogPathSetForRingLogger(t *testing.T) {
|
|
|
+ containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForRingLogger")
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ c := &Container{
|
|
|
+ Config: &container.Config{},
|
|
|
+ HostConfig: &container.HostConfig{
|
|
|
+ LogConfig: container.LogConfig{
|
|
|
+ Type: jsonfilelog.Name,
|
|
|
+ Config: map[string]string{
|
|
|
+ "mode": string(container.LogModeNonBlock),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ID: "TestContainerLogPathSetForRingLogger",
|
|
|
+ Root: containerRoot,
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = c.StartLogger()
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID)))
|
|
|
+ require.NoError(t, err)
|
|
|
+ require.Equal(t, c.LogPath, expectedLogPath)
|
|
|
+}
|