forked from maier/circonus-gometrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcirconus-gometrics_test.go
85 lines (63 loc) · 2.3 KB
/
circonus-gometrics_test.go
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
// 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 (
"errors"
"testing"
)
func TestNewCirconusMetricsInvalidConfig(t *testing.T) {
t.Log("Testing correct error return when no config supplied")
expectedError := errors.New("Invalid configuration (nil).")
_, err := NewCirconusMetrics(nil)
if err == nil || err.Error() != expectedError.Error() {
t.Errorf("Expected an '%#v' error, got '%#v'", expectedError, err)
}
}
func TestNewCirconusMetricsNoTokenNoUrl(t *testing.T) {
t.Log("Testing correct error return when no API Token and no Submission URL supplied")
expectedError := errors.New("Invalid check manager configuration (no API token AND no submission url).")
cfg := &Config{}
_, err := NewCirconusMetrics(cfg)
if err == nil || err.Error() != expectedError.Error() {
t.Errorf("Expected an '%#v' error, got '%#v'", expectedError, err)
}
}
func TestNewCirconusMetricsHttpUrlNoToken(t *testing.T) {
t.Log("Testing correct return with Submission URL (http) and no API Token supplied")
cfg := &Config{}
cfg.CheckManager.Check.SubmissionURL = "http://127.0.0.1:56104"
cm, err := NewCirconusMetrics(cfg)
if err != nil {
t.Errorf("Expected no error, got '%v'", err)
}
trap, err := cm.check.GetTrap()
if err != nil {
t.Errorf("Expected no error, got '%v'", err)
}
if trap.URL.String() != cfg.CheckManager.Check.SubmissionURL {
t.Errorf("Expected '%s' == '%s'", trap.URL.String(), cfg.CheckManager.Check.SubmissionURL)
}
if trap.TLS != nil {
t.Errorf("Expected nil found %#v", trap.TLS)
}
}
func TestNewCirconusMetricsHttpsUrlNoToken(t *testing.T) {
t.Log("Testing correct return with Submission URL (https) and no API Token supplied")
cfg := &Config{}
cfg.CheckManager.Check.SubmissionURL = "https://127.0.0.1/v2"
cm, err := NewCirconusMetrics(cfg)
if err != nil {
t.Errorf("Expected no error, got '%v'", err)
}
trap, err := cm.check.GetTrap()
if err != nil {
t.Errorf("Expected no error, got '%v'", err)
}
if trap.URL.String() != cfg.CheckManager.Check.SubmissionURL {
t.Errorf("Expected '%s' == '%s'", trap.URL.String(), cfg.CheckManager.Check.SubmissionURL)
}
if trap.TLS == nil {
t.Errorf("Expected a x509 cert pool, found nil")
}
}