bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/conf/conf_test.go (about)

     1  package conf
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  
     7  	"bosun.org/opentsdb"
     8  )
     9  
    10  func TestSquelch(t *testing.T) {
    11  	s := Squelches{
    12  		map[string]*regexp.Regexp{
    13  			"x": regexp.MustCompile("ab"),
    14  			"y": regexp.MustCompile("bc"),
    15  		},
    16  		map[string]*regexp.Regexp{
    17  			"x": regexp.MustCompile("ab"),
    18  			"z": regexp.MustCompile("de"),
    19  		},
    20  	}
    21  	type squelchTest struct {
    22  		tags   opentsdb.TagSet
    23  		expect bool
    24  	}
    25  	tests := []squelchTest{
    26  		{
    27  			opentsdb.TagSet{
    28  				"x": "ab",
    29  			},
    30  			false,
    31  		},
    32  		{
    33  			opentsdb.TagSet{
    34  				"x": "abe",
    35  				"y": "obcx",
    36  			},
    37  			true,
    38  		},
    39  		{
    40  			opentsdb.TagSet{
    41  				"x": "abe",
    42  				"z": "obcx",
    43  			},
    44  			false,
    45  		},
    46  		{
    47  			opentsdb.TagSet{
    48  				"x": "abe",
    49  				"z": "ouder",
    50  			},
    51  			true,
    52  		},
    53  		{
    54  			opentsdb.TagSet{
    55  				"x": "ae",
    56  				"y": "bc",
    57  				"z": "de",
    58  			},
    59  			false,
    60  		},
    61  	}
    62  	for _, test := range tests {
    63  		got := s.Squelched(test.tags)
    64  		if got != test.expect {
    65  			t.Errorf("for %v got %v, expected %v", test.tags, got, test.expect)
    66  		}
    67  	}
    68  }