|
@@ -2,6 +2,7 @@ package dockeracquisition
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "encoding/binary"
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
"os"
|
|
"os"
|
|
@@ -22,6 +23,8 @@ import (
|
|
|
|
|
|
const testContainerName = "docker_test"
|
|
const testContainerName = "docker_test"
|
|
|
|
|
|
|
|
+var readLogs = false
|
|
|
|
+
|
|
func TestConfigure(t *testing.T) {
|
|
func TestConfigure(t *testing.T) {
|
|
log.Infof("Test 'TestConfigure'")
|
|
log.Infof("Test 'TestConfigure'")
|
|
|
|
|
|
@@ -159,6 +162,7 @@ container_name_regexp:
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ readLogs = false
|
|
dockerTomb := tomb.Tomb{}
|
|
dockerTomb := tomb.Tomb{}
|
|
out := make(chan types.Event)
|
|
out := make(chan types.Event)
|
|
dockerSource := DockerSource{}
|
|
dockerSource := DockerSource{}
|
|
@@ -188,13 +192,11 @@ container_name_regexp:
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- time.Sleep(10 * time.Second)
|
|
|
|
cstest.AssertErrorContains(t, err, ts.expectedErr)
|
|
cstest.AssertErrorContains(t, err, ts.expectedErr)
|
|
|
|
|
|
if err := readerTomb.Wait(); err != nil {
|
|
if err := readerTomb.Wait(); err != nil {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
- //time.Sleep(4 * time.Second)
|
|
|
|
if ts.expectedLines != 0 {
|
|
if ts.expectedLines != 0 {
|
|
assert.Equal(t, ts.expectedLines, actualLines)
|
|
assert.Equal(t, ts.expectedLines, actualLines)
|
|
}
|
|
}
|
|
@@ -207,6 +209,9 @@ container_name_regexp:
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *mockDockerCli) ContainerList(ctx context.Context, options dockerTypes.ContainerListOptions) ([]dockerTypes.Container, error) {
|
|
func (cli *mockDockerCli) ContainerList(ctx context.Context, options dockerTypes.ContainerListOptions) ([]dockerTypes.Container, error) {
|
|
|
|
+ if readLogs == true {
|
|
|
|
+ return []dockerTypes.Container{}, nil
|
|
|
|
+ }
|
|
containers := make([]dockerTypes.Container, 0)
|
|
containers := make([]dockerTypes.Container, 0)
|
|
container := &dockerTypes.Container{
|
|
container := &dockerTypes.Container{
|
|
ID: "12456",
|
|
ID: "12456",
|
|
@@ -218,11 +223,17 @@ func (cli *mockDockerCli) ContainerList(ctx context.Context, options dockerTypes
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *mockDockerCli) ContainerLogs(ctx context.Context, container string, options dockerTypes.ContainerLogsOptions) (io.ReadCloser, error) {
|
|
func (cli *mockDockerCli) ContainerLogs(ctx context.Context, container string, options dockerTypes.ContainerLogsOptions) (io.ReadCloser, error) {
|
|
- startLineByte := "\x01\x00\x00\x00\x00\x00\x00\x1f"
|
|
|
|
- data := []string{"docker", "test", "1234"}
|
|
|
|
|
|
+ if readLogs == true {
|
|
|
|
+ return io.NopCloser(strings.NewReader("")), nil
|
|
|
|
+ }
|
|
|
|
+ readLogs = true
|
|
|
|
+ data := []string{"docker\n", "test\n", "1234\n"}
|
|
ret := ""
|
|
ret := ""
|
|
for _, line := range data {
|
|
for _, line := range data {
|
|
- ret += fmt.Sprintf("%s%s\n", startLineByte, line)
|
|
|
|
|
|
+ startLineByte := make([]byte, 8)
|
|
|
|
+ binary.LittleEndian.PutUint32(startLineByte, 1) //stdout stream
|
|
|
|
+ binary.BigEndian.PutUint32(startLineByte[4:], uint32(len(line)))
|
|
|
|
+ ret += fmt.Sprintf("%s%s", startLineByte, line)
|
|
}
|
|
}
|
|
r := io.NopCloser(strings.NewReader(ret)) // r type is io.ReadCloser
|
|
r := io.NopCloser(strings.NewReader(ret)) // r type is io.ReadCloser
|
|
return r, nil
|
|
return r, nil
|
|
@@ -281,6 +292,7 @@ func TestOneShot(t *testing.T) {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ readLogs = false
|
|
dockerClient := &DockerSource{}
|
|
dockerClient := &DockerSource{}
|
|
labels := make(map[string]string)
|
|
labels := make(map[string]string)
|
|
labels["type"] = ts.logType
|
|
labels["type"] = ts.logType
|