Skip to content

Commit

Permalink
fix spec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Aug 9, 2018
1 parent f74e424 commit 206b1f4
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 79 deletions.
15 changes: 6 additions & 9 deletions spec/cloud_test.go
Expand Up @@ -9,6 +9,8 @@ import (
"reflect"
"testing"

"github.com/mackerelio/mackerel-client-go"

"github.com/mackerelio/mackerel-agent/config"
)

Expand All @@ -32,19 +34,14 @@ func TestCloudGenerate(t *testing.T) {
t.Errorf("should not raise error: %s", err)
}

cloud, typeOk := value.(map[string]interface{})
cloud, typeOk := value.(*mackerel.Cloud)
if !typeOk {
t.Errorf("value should be map. %+v", value)
}

value, ok := cloud["metadata"]
if !ok {
t.Error("results should have metadata.")
t.Errorf("value should be *mackerel.Cloud. %+v", value)
}

metadata, typeOk := value.(map[string]string)
metadata, typeOk := cloud.MetaData.(map[string]string)
if !typeOk {
t.Errorf("v should be map. %+v", value)
t.Errorf("MetaData should be map. %+v", cloud.MetaData)
}

if len(metadata["instance-id"]) == 0 {
Expand Down
10 changes: 7 additions & 3 deletions spec/darwin/cpu_test.go
Expand Up @@ -2,7 +2,11 @@

package darwin

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestCPUGenerator_Generate(t *testing.T) {
g := &CPUGenerator{}
Expand All @@ -12,9 +16,9 @@ func TestCPUGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

cpus, ok := result.([]cpuSpec)
cpus, ok := result.(mackerel.CPU)
if !ok {
t.Fatalf("the result must be of type []cpuSpec: %T", result)
t.Fatalf("the result must be of type mackerel.CPU: %T", result)
}

if len(cpus) == 0 {
Expand Down
10 changes: 7 additions & 3 deletions spec/darwin/kernel_test.go
Expand Up @@ -2,7 +2,11 @@

package darwin

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestKernelGenerator_Generate(t *testing.T) {
g := &KernelGenerator{}
Expand All @@ -12,9 +16,9 @@ func TestKernelGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

kernel, ok := result.(map[string]string)
kernel, ok := result.(mackerel.Kernel)
if !ok {
t.Fatalf("the result must be of type map[string]string: %t", result)
t.Fatalf("the result must be of type mackerel.Kernel: %t", result)
}

_, osExists := kernel["os"]
Expand Down
4 changes: 3 additions & 1 deletion spec/darwin/memory_test.go
Expand Up @@ -5,6 +5,8 @@ package darwin
import (
"regexp"
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestMemoryGenerator_Generate(t *testing.T) {
Expand All @@ -15,7 +17,7 @@ func TestMemoryGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

memorySpecs := result.(map[string]string)
memorySpecs := result.(mackerel.Memory)
totalMemory, ok := memorySpecs["total"]
if !ok {
t.Error("'total' key must exist")
Expand Down
10 changes: 7 additions & 3 deletions spec/filesystem_test.go
Expand Up @@ -2,7 +2,11 @@

package spec

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestFilesystemGenerate(t *testing.T) {
g := &FilesystemGenerator{}
Expand All @@ -12,8 +16,8 @@ func TestFilesystemGenerate(t *testing.T) {
t.Skipf("Generate() failed: %s", err)
}

_, resultTypeOk := result.(map[string]map[string]interface{})
_, resultTypeOk := result.(mackerel.FileSystem)
if !resultTypeOk {
t.Errorf("Return type of Generate() shuold be map[string]map[string]interface{}")
t.Errorf("Return type of Generate() shuold be mackerel.FileSystem")
}
}
10 changes: 7 additions & 3 deletions spec/freebsd/cpu_test.go
Expand Up @@ -2,7 +2,11 @@

package freebsd

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestCPUGenerator_Generate(t *testing.T) {
g := &CPUGenerator{}
Expand All @@ -12,9 +16,9 @@ func TestCPUGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

cpus, ok := result.([]cpuSpec)
cpus, ok := result.(mackerel.CPU)
if !ok {
t.Fatalf("the result must be of type []cpuSpec: %T", result)
t.Fatalf("the result must be of type mackerel.CPU: %T", result)
}

if len(cpus) == 0 {
Expand Down
10 changes: 7 additions & 3 deletions spec/freebsd/kernel_test.go
Expand Up @@ -2,7 +2,11 @@

package freebsd

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestKernelGenerator_Generate(t *testing.T) {
g := &KernelGenerator{}
Expand All @@ -12,9 +16,9 @@ func TestKernelGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

kernel, ok := result.(map[string]string)
kernel, ok := result.(mackerel.Kernel)
if !ok {
t.Fatalf("the result must be of type map[string]string: %t", result)
t.Fatalf("the result must be of type mackerel.Kernel: %t", result)
}

_, osExists := kernel["os"]
Expand Down
4 changes: 3 additions & 1 deletion spec/freebsd/memory_test.go
Expand Up @@ -5,6 +5,8 @@ package freebsd
import (
"regexp"
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestMemoryGenerator_Generate(t *testing.T) {
Expand All @@ -15,7 +17,7 @@ func TestMemoryGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

memorySpecs := result.(map[string]string)
memorySpecs := result.(mackerel.Memory)
totalMemory, ok := memorySpecs["total"]
if !ok {
t.Error("'total' key must exist")
Expand Down
6 changes: 4 additions & 2 deletions spec/linux/block_device_test.go
Expand Up @@ -5,6 +5,8 @@ package linux
import (
"regexp"
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func hasValidBlockDeviceValueForKey(t *testing.T, deviceInfo map[string]interface{}, key string) {
Expand All @@ -23,9 +25,9 @@ func TestBlockDeviceGenerate(t *testing.T) {
t.Errorf("should not raise error: %v", err)
}

blockDevice, typeOk := value.(map[string]map[string]interface{})
blockDevice, typeOk := value.(mackerel.BlockDevice)
if !typeOk {
t.Errorf("value should be slice of map. %+v", value)
t.Errorf("value should be mackerel.BlockDevice. %+v", value)
}

sda, ok := blockDevice["sda"]
Expand Down
22 changes: 12 additions & 10 deletions spec/linux/cpu_test.go
Expand Up @@ -5,6 +5,8 @@ package linux
import (
"bytes"
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestCPUGenerate(t *testing.T) {
Expand All @@ -14,9 +16,9 @@ func TestCPUGenerate(t *testing.T) {
t.Errorf("should not raise error: %v", err)
}

cpu, typeOk := value.([]map[string]interface{})
cpu, typeOk := value.(mackerel.CPU)
if !typeOk {
t.Errorf("value should be slice of map. %+v", value)
t.Errorf("value should be mackerel.CPU. %+v", value)
}

if len(cpu) == 0 {
Expand Down Expand Up @@ -120,9 +122,9 @@ power management:`
t.Errorf("should not raise error: %v", err)
}

cpus, typeOk := value.([]map[string]interface{})
cpus, typeOk := value.(mackerel.CPU)
if !typeOk {
t.Errorf("value should be slice of map. %+v", value)
t.Errorf("value should be mackerel.CPU. %+v", value)
}

if len(cpus) != 2 {
Expand Down Expand Up @@ -198,9 +200,9 @@ Revision : 1a01040`
t.Errorf("should not raise error: %v", err)
}

cpus, typeOk := value.([]map[string]interface{})
cpus, typeOk := value.(mackerel.CPU)
if !typeOk {
t.Errorf("value should be slice of map. %+v", value)
t.Errorf("value should be mackerel.CPU. %+v", value)
}

if len(cpus) != 4 {
Expand Down Expand Up @@ -249,9 +251,9 @@ Serial : 0000000000000000`
t.Errorf("should not raise error: %v", err)
}

cpus, typeOk := value.([]map[string]interface{})
cpus, typeOk := value.(mackerel.CPU)
if !typeOk {
t.Errorf("value should be slice of map. %+v", value)
t.Errorf("value should be mackerel.CPU. %+v", value)
}

if len(cpus) != 4 {
Expand Down Expand Up @@ -289,9 +291,9 @@ Serial : 0000000000000000`
t.Errorf("should not raise error: %v", err)
}

cpus, typeOk := value.([]map[string]interface{})
cpus, typeOk := value.(mackerel.CPU)
if !typeOk {
t.Errorf("value should be slice of map. %+v", value)
t.Errorf("value should be mackerel.CPU. %+v", value)
}

if len(cpus) != 1 {
Expand Down
6 changes: 4 additions & 2 deletions spec/linux/kernel_test.go
Expand Up @@ -4,6 +4,8 @@ package linux

import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestKernelGenerate(t *testing.T) {
Expand All @@ -13,9 +15,9 @@ func TestKernelGenerate(t *testing.T) {
t.Errorf("should not raise error: %s", err)
}

kernel, typeOk := value.(map[string]string)
kernel, typeOk := value.(mackerel.Kernel)
if !typeOk {
t.Errorf("value should be map. %+v", value)
t.Errorf("value should be mackerel.Kernel. %+v", value)
}

if len(kernel["name"]) == 0 {
Expand Down
8 changes: 5 additions & 3 deletions spec/linux/memory_test.go
Expand Up @@ -6,6 +6,8 @@ import (
"reflect"
"strings"
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestMemoryGenerator(t *testing.T) {
Expand All @@ -15,9 +17,9 @@ func TestMemoryGenerator(t *testing.T) {
t.Errorf("should not raise error: %v", err)
}

memory, typeOk := value.(map[string]string)
memory, typeOk := value.(mackerel.Memory)
if !typeOk {
t.Errorf("value should be map. %+v", value)
t.Errorf("value should be mackerel.Memory. %+v", value)
}

memItemKeys := []string{
Expand Down Expand Up @@ -104,7 +106,7 @@ DirectMap1G: 12582912 kB
if err != nil {
t.Errorf("should not raise error: %v", err)
}
expected := map[string]string{
expected := mackerel.Memory{
"total": "15434208kB",
"free": "3009856kB",
"buffers": "443104kB",
Expand Down
10 changes: 7 additions & 3 deletions spec/netbsd/cpu_test.go
Expand Up @@ -2,7 +2,11 @@

package netbsd

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestCPUGenerator_Generate(t *testing.T) {
g := &CPUGenerator{}
Expand All @@ -12,9 +16,9 @@ func TestCPUGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

cpus, ok := result.([]cpuSpec)
cpus, ok := result.(mackerel.CPU)
if !ok {
t.Fatalf("the result must be of type []cpuSpec: %T", result)
t.Fatalf("the result must be of type mackerel.CPU: %T", result)
}

if len(cpus) == 0 {
Expand Down
10 changes: 7 additions & 3 deletions spec/netbsd/kernel_test.go
Expand Up @@ -2,7 +2,11 @@

package netbsd

import "testing"
import (
"testing"

"github.com/mackerelio/mackerel-client-go"
)

func TestKernelGenerator_Generate(t *testing.T) {
g := &KernelGenerator{}
Expand All @@ -12,9 +16,9 @@ func TestKernelGenerator_Generate(t *testing.T) {
t.Errorf("Generate() must not fail: %s", err)
}

kernel, ok := result.(map[string]string)
kernel, ok := result.(mackerel.Kernel)
if !ok {
t.Fatalf("the result must be of type map[string]string: %t", result)
t.Fatalf("the result must be of type mackerel.Kernel: %t", result)
}

_, osExists := kernel["os"]
Expand Down

0 comments on commit 206b1f4

Please sign in to comment.