File: text_test.go

package info (click to toggle)
golang-github-circonus-labs-circonus-gometrics 2.3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 824 kB
  • sloc: makefile: 2
file content (123 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (4)
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
// 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 circonusgometrics

import (
	"testing"
)

func TestSetText(t *testing.T) {
	t.Log("Testing gauge.SetText")

	cm := &CirconusMetrics{}
	cm.text = make(map[string]string)
	cm.SetText("foo", "bar")

	val, ok := cm.text["foo"]
	if !ok {
		t.Errorf("Expected to find foo")
	}

	if val != "bar" {
		t.Errorf("Expected 'bar', found '%s'", val)
	}
}

func TestSetTextValue(t *testing.T) {
	t.Log("Testing gauge.SetTextValue")

	cm := &CirconusMetrics{}
	cm.text = make(map[string]string)
	cm.SetTextValue("foo", "bar")

	val, ok := cm.text["foo"]
	if !ok {
		t.Errorf("Expected to find foo")
	}

	if val != "bar" {
		t.Errorf("Expected 'bar', found '%s'", val)
	}
}

func TestRemoveText(t *testing.T) {
	t.Log("Testing text.RemoveText")

	cm := &CirconusMetrics{}
	cm.text = make(map[string]string)
	cm.SetText("foo", "bar")

	val, ok := cm.text["foo"]
	if !ok {
		t.Errorf("Expected to find foo")
	}

	if val != "bar" {
		t.Errorf("Expected 'bar', found '%s'", val)
	}

	cm.RemoveText("foo")

	val, ok = cm.text["foo"]
	if ok {
		t.Errorf("Expected NOT to find foo")
	}

	if val != "" {
		t.Errorf("Expected '', found '%s'", val)
	}
}

func TestSetTextFunc(t *testing.T) {
	t.Log("Testing text.SetTextFunc")

	tf := func() string {
		return "bar"
	}
	cm := &CirconusMetrics{}
	cm.textFuncs = make(map[string]func() string)
	cm.SetTextFunc("foo", tf)

	val, ok := cm.textFuncs["foo"]
	if !ok {
		t.Errorf("Expected to find foo")
	}

	if val() != "bar" {
		t.Errorf("Expected 'bar', found '%s'", val())
	}
}

func TestRemoveTextFunc(t *testing.T) {
	t.Log("Testing text.RemoveTextFunc")

	tf := func() string {
		return "bar"
	}
	cm := &CirconusMetrics{}
	cm.textFuncs = make(map[string]func() string)
	cm.SetTextFunc("foo", tf)

	val, ok := cm.textFuncs["foo"]
	if !ok {
		t.Errorf("Expected to find foo")
	}

	if val() != "bar" {
		t.Errorf("Expected 'bar', found '%s'", val())
	}

	cm.RemoveTextFunc("foo")

	val, ok = cm.textFuncs["foo"]
	if ok {
		t.Errorf("Expected NOT to find foo")
	}

	if val != nil {
		t.Errorf("Expected nil, found %s", val())
	}

}