File: cert_test.go

package info (click to toggle)
golang-github-circonus-labs-circonus-gometrics 0.0~git20160822.0.2f5be48-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 236 kB
  • ctags: 202
  • sloc: makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download
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
// 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 (
	"os"
	"testing"

	"github.com/circonus-labs/circonus-gometrics/api"
)

func TestLoadCertNoToken(t *testing.T) {
	t.Log("Testing cert load w/o API token")

	cm := &CheckManager{}
	cm.enabled = false

	cm.loadCACert()

	if cm.certPool == nil {
		t.Errorf("Expected cert pool to be initialized, still nil.")
	}

	subjs := cm.certPool.Subjects()
	if len(subjs) == 0 {
		t.Errorf("Expected > 0 certs in pool")
	}
}

func TestLoadCertWithToken(t *testing.T) {
	if os.Getenv("CIRCONUS_API_TOKEN") == "" {
		t.Skip("skipping test; $CIRCONUS_API_TOKEN not set")
	}

	t.Log("Testing cert load with API token")

	cm := &CheckManager{}
	ac := &api.Config{}
	ac.TokenKey = os.Getenv("CIRCONUS_API_TOKEN")
	apih, err := api.NewAPI(ac)
	if err != nil {
		t.Errorf("Expected no error, got '%v'", err)
	}
	cm.apih = apih
	cm.enabled = true

	cm.loadCACert()

	if cm.certPool == nil {
		t.Errorf("Expected cert pool to be initialized, still nil.")
	}

	subjs := cm.certPool.Subjects()
	if len(subjs) == 0 {
		t.Errorf("Expected > 0 certs in pool")
	}
}