File: checkbundle_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 (71 lines) | stat: -rw-r--r-- 1,818 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
60
61
62
63
64
65
66
67
68
69
70
71
// 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 api

import (
	"fmt"
	"os"
	"reflect"
	"strconv"
	"testing"
)

// Implicit tests:
//
// FetchCheckBundleByCID is called by FetchCheckBundleByID
//
// Excluded tests:
//
// CreateCheckBundle and UpdateCheckBundle because
// both calls change an account (creating and updating)
// checks/check bundles they are tested in checkmgr.

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

	t.Log("Testing correct return from API call")

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

	cid := os.Getenv("CIRC_API_TEST_CHECK_BUNDLE_ID")
	if cid == "" {
		t.Fatal("Invalid check bundle id (empty)")
	}

	id, err := strconv.Atoi(cid)
	if err != nil {
		t.Fatalf("Unable to convert check bundle id %s to int", cid)
	}

	checkBundleID := IDType(id)

	checkBundle, err := apih.FetchCheckBundleByID(checkBundleID)
	if err != nil {
		t.Fatalf("Expected no error, got '%v'", err)
	}

	actualType := reflect.TypeOf(checkBundle)
	expectedType := "*api.CheckBundle"
	if actualType.String() != expectedType {
		t.Errorf("Expected %s, got %s", expectedType, actualType.String())
	}

	expectedCid := fmt.Sprintf("/check_bundle/%s", strconv.Itoa(int(checkBundleID)))
	if checkBundle.Cid != expectedCid {
		t.Fatalf("%s != %s", checkBundle.Cid, expectedCid)
	}

	t.Logf("Check bundle returned %s %s", checkBundle.DisplayName, checkBundle.Cid)
}