From 23496fdf0373e598452e2ed6aec1f48001ca3b06 Mon Sep 17 00:00:00 2001 From: Lei Xue Date: Sat, 9 Jan 2016 09:16:31 +0800 Subject: [PATCH 1/2] fix compile issue of influxdb test --- storage/influxdb/influxdb_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/storage/influxdb/influxdb_test.go b/storage/influxdb/influxdb_test.go index 39433ae6..12302f3b 100644 --- a/storage/influxdb/influxdb_test.go +++ b/storage/influxdb/influxdb_test.go @@ -107,6 +107,7 @@ func (self *influxDbTestStorageDriver) StatsEq(a, b *info.ContainerStats) bool { func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T, bufferCount int) { machineName := "machineA" + table := "cadvisor_table" database := "cadvisor_test" username := "root" password := "root" @@ -131,7 +132,8 @@ func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T, bu // Delete all data by the end of the call. //defer client.Query(influxdb.Query{Command: fmt.Sprintf("drop database \"%v\"", database)}) - driver, err := New(machineName, + driver, err := newStorage(machineName, + table, database, username, password, @@ -150,7 +152,8 @@ func runStorageTest(f func(test.TestStorageDriver, *testing.T), t *testing.T, bu test.StorageDriverFillRandomStatsFunc("containerOnSameMachine", 100, testDriver, t) // Generate another container's data on another machine. - driverForAnotherMachine, err := New("machineB", + driverForAnotherMachine, err := newStorage("machineB", + table, database, username, password, @@ -198,12 +201,14 @@ func TestContainerFileSystemStatsToPoints(t *testing.T) { assert := assert.New(t) machineName := "testMachine" + table := "cadvisor_table" database := "cadvisor_test" username := "root" password := "root" influxdbHost := "localhost:8086" - storage, err := New(machineName, + storage, err := newStorage(machineName, + table, database, username, password, @@ -267,12 +272,14 @@ func assertContainsPointWithValue(t *testing.T, points []*influxdb.Point, name s func createTestStorage() (*influxdbStorage, error) { machineName := "testMachine" + table := "cadvisor_table" database := "cadvisor_test" username := "root" password := "root" influxdbHost := "localhost:8086" - storage, err := New(machineName, + storage, err := newStorage(machineName, + table, database, username, password, From 5b7a2fbd450beabae8d6a8fb5287b9f66c07535e Mon Sep 17 00:00:00 2001 From: Lei Xue Date: Sat, 9 Jan 2016 09:20:11 +0800 Subject: [PATCH 2/2] refactor the function of StatsEq --- storage/influxdb/influxdb_test.go | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/storage/influxdb/influxdb_test.go b/storage/influxdb/influxdb_test.go index 12302f3b..f25b12a6 100644 --- a/storage/influxdb/influxdb_test.go +++ b/storage/influxdb/influxdb_test.go @@ -61,31 +61,9 @@ func (self *influxDbTestStorageDriver) StatsEq(a, b *info.ContainerStats) bool { return false } // Check only the stats populated in influxdb. - if a.Cpu.Usage.Total != b.Cpu.Usage.Total { + if !reflect.DeepEqual(a.Cpu.Usage, b.Cpu.Usage) { return false } - if a.Cpu.Usage.System != b.Cpu.Usage.System { - return false - } - if a.Cpu.Usage.User != b.Cpu.Usage.User { - return false - } - - // TODO simpler way to check if arrays are equal? - if a.Cpu.Usage.PerCpu == nil && b.Cpu.Usage.PerCpu != nil { - return false - } - if a.Cpu.Usage.PerCpu != nil && b.Cpu.Usage.PerCpu == nil { - return false - } - if len(a.Cpu.Usage.PerCpu) != len(b.Cpu.Usage.PerCpu) { - return false - } - for i, usage := range a.Cpu.Usage.PerCpu { - if usage != b.Cpu.Usage.PerCpu[i] { - return false - } - } if a.Memory.Usage != b.Memory.Usage { return false