1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// Copyright 2016 Circonus, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package checkmgr
import (
"testing"
"github.com/circonus-labs/circonus-gometrics/api"
)
func TestIsMetricActive(t *testing.T) {
t.Log("Testing correct return from IsMetricActive")
cm := &CheckManager{}
cm.availableMetrics = map[string]bool{
"foo": true,
}
t.Log("Testing for 'foo', foo in list")
if !cm.IsMetricActive("foo") {
t.Error("Expected true")
}
t.Log("Testing for 'bar', bar not in list")
if cm.IsMetricActive("bar") {
t.Error("Expected false")
}
}
func TestInventoryMetrics(t *testing.T) {
t.Log("Testing correct return from InventoryMetrics")
cm := &CheckManager{}
cm.checkBundle = &api.CheckBundle{}
cm.checkBundle.Metrics = []api.CheckBundleMetric{
api.CheckBundleMetric{
Name: "foo",
Type: "numeric",
Status: "active",
},
}
cm.availableMetrics = make(map[string]bool)
t.Log("Testing for 'foo', foo not in list")
if cm.IsMetricActive("foo") {
t.Error("Expected false")
}
t.Log("Inventory metrics in check bundle")
cm.inventoryMetrics()
t.Log("Testing for 'foo', foo in list")
if !cm.IsMetricActive("foo") {
t.Error("Expected true")
}
t.Log("Testing for 'bar', bar not in list")
if cm.IsMetricActive("bar") {
t.Error("Expected false")
}
}
func TestActivateMetric(t *testing.T) {
t.Log("Testing correct return from ActivateMetric")
cm := &CheckManager{}
cm.checkBundle = &api.CheckBundle{}
cm.checkBundle.Metrics = []api.CheckBundleMetric{
api.CheckBundleMetric{
Name: "foo",
Type: "numeric",
Status: "active",
},
}
cm.availableMetrics = make(map[string]bool)
cm.forceMetricActivation = false
t.Log("Testing for 'foo', foo not in list")
if !cm.ActivateMetric("foo") {
t.Error("Expected true")
}
t.Log("Inventory metrics in check bundle")
cm.inventoryMetrics()
t.Log("Testing for 'foo', foo in list")
if cm.ActivateMetric("foo") {
t.Error("Expected false")
}
cm.checkBundle.Metrics = []api.CheckBundleMetric{
api.CheckBundleMetric{
Name: "bar",
Type: "numeric",
Status: "available",
},
}
t.Log("Testing for 'bar', bar not in list")
if !cm.ActivateMetric("bar") {
t.Error("Expected true")
}
t.Log("Inventory metrics in check bundle")
cm.inventoryMetrics()
t.Log("Testing for 'bar', bar in list[false]")
if cm.ActivateMetric("bar") {
t.Error("Expected false")
}
t.Log("Change forceMetricActivation to true")
cm.forceMetricActivation = true
t.Log("Testing for 'bar', bar in list[false]")
if !cm.ActivateMetric("bar") {
t.Error("Expected true")
}
}
|