bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/collectors_test.go (about)

     1  package collectors
     2  
     3  import (
     4  	"testing"
     5  
     6  	"bosun.org/host"
     7  	"bosun.org/util"
     8  
     9  	"bosun.org/opentsdb"
    10  )
    11  
    12  func TestIsDigit(t *testing.T) {
    13  	numbers := []string{"029", "1", "400"}
    14  	not_numbers := []string{"1a3", " 3", "-1", "3.0", "am"}
    15  	for _, s := range not_numbers {
    16  		if IsDigit(s) {
    17  			t.Errorf("%s: not expected to be a digit", s)
    18  		}
    19  	}
    20  	for _, n := range numbers {
    21  		if !IsDigit(n) {
    22  			t.Errorf("%s: expected to be a digit", n)
    23  		}
    24  	}
    25  }
    26  
    27  func TestAddTS_Invalid(t *testing.T) {
    28  	hm, err := host.NewManager(false)
    29  	if err != nil {
    30  		t.Error(err)
    31  	}
    32  
    33  	util.SetHostManager(hm)
    34  
    35  	mdp := &opentsdb.MultiDataPoint{}
    36  	ts := opentsdb.TagSet{"srv": "%%%"}
    37  	Add(mdp, "aaaa", 42, ts, "", "", "") //don't have a good way to tesst this automatically, but I look for a log message with this line number in it.
    38  	if len(*mdp) != 0 {
    39  		t.Fatal("Shouldn't have added invalid tags.")
    40  	}
    41  }