Skip to content

Commit

Permalink
Fix docker input unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson committed Jun 21, 2019
1 parent 791d154 commit f405bca
Showing 1 changed file with 32 additions and 53 deletions.
85 changes: 32 additions & 53 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,13 @@ func TestContainerStatus(t *testing.T) {
// tags
Status string
// fields
OOMKilled bool
Pid int
ExitCode int
StartedAt time.Time
FinishedAt time.Time
UptimeNs int64
ContainerID string
OOMKilled bool
Pid int
ExitCode int
StartedAt time.Time
FinishedAt time.Time
UptimeNs int64
}

var tests = []struct {
Expand All @@ -564,12 +565,13 @@ func TestContainerStatus(t *testing.T) {
},
inspect: containerInspect(),
expect: expectation{
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
StartedAt: time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC),
UptimeNs: int64(3 * time.Minute),
ContainerID: "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
StartedAt: time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC),
UptimeNs: int64(3 * time.Minute),
},
},
{
Expand All @@ -580,13 +582,14 @@ func TestContainerStatus(t *testing.T) {
return i
}(),
expect: expectation{
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
StartedAt: time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC),
FinishedAt: time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC),
UptimeNs: int64(5 * time.Minute),
ContainerID: "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
StartedAt: time.Date(2018, 6, 14, 5, 48, 53, 266176036, time.UTC),
FinishedAt: time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC),
UptimeNs: int64(5 * time.Minute),
},
},
{
Expand All @@ -598,11 +601,12 @@ func TestContainerStatus(t *testing.T) {
return i
}(),
expect: expectation{
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
FinishedAt: time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC),
ContainerID: "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
FinishedAt: time.Date(2018, 6, 14, 5, 53, 53, 266176036, time.UTC),
},
},
}
Expand Down Expand Up @@ -636,9 +640,10 @@ func TestContainerStatus(t *testing.T) {
require.NoError(t, err)

fields := map[string]interface{}{
"oomkilled": tt.expect.OOMKilled,
"pid": tt.expect.Pid,
"exitcode": tt.expect.ExitCode,
"oomkilled": tt.expect.OOMKilled,
"pid": tt.expect.Pid,
"exitcode": tt.expect.ExitCode,
"container_id": tt.expect.ContainerID,
}

if started := tt.expect.StartedAt; !started.IsZero() {
Expand Down Expand Up @@ -756,32 +761,6 @@ func TestDockerGatherInfo(t *testing.T) {
"container_status": "running",
},
)

acc.AssertContainsTaggedFields(t,
"docker_container_status",
map[string]interface{}{
"container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
"exitcode": int(0),
"oomkilled": false,
"pid": int(1234),
"started_at": int64(1528955333266176036),
//"finished_at": float64(0),
},
map[string]string{
"engine_host": "absol",
"container_name": "etcd2",
"container_image": "quay.io:4443/coreos/etcd",
"container_version": "v2.2.2",
"ENVVAR1": "loremipsum",
"ENVVAR2": "dolorsitamet",
"ENVVAR3": "=ubuntu:10.04",
"ENVVAR7": "ENVVAR8=ENVVAR9",
"label1": "test_value_1",
"label2": "test_value_2",
"server_version": "17.09.0-ce",
"container_status": "running",
},
)
}

func TestDockerGatherSwarmInfo(t *testing.T) {
Expand Down

0 comments on commit f405bca

Please sign in to comment.