Refactor docs; Add 'ipng_source_tag', add udp listener for nginx-ipng-stats plugin
This commit is contained in:
@@ -335,3 +335,45 @@ func TestDimensionLabelASN(t *testing.T) {
|
||||
t.Errorf("DimensionLabel ASN: got %q, want %q", got, "12345")
|
||||
}
|
||||
}
|
||||
|
||||
// --- SourceTag label encoding, filtering, and DimensionLabel ---
|
||||
|
||||
func TestEncodeLabelTupleRoundtripWithSourceTag(t *testing.T) {
|
||||
for _, tag := range []string{"", "direct", "cdn", "tag with spaces"} {
|
||||
orig := Tuple6{Website: "a.com", Prefix: "1.2.3.0/24", URI: "/x", Status: "200", SourceTag: tag}
|
||||
got := LabelTuple(EncodeTuple(orig))
|
||||
if got != orig {
|
||||
t.Errorf("roundtrip mismatch for tag=%q: got %+v, want %+v", tag, got, orig)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelTupleBackwardCompatNoSourceTag(t *testing.T) {
|
||||
// 6-field label (pre-source_tag snapshot) decodes with SourceTag="".
|
||||
label := "a.com\x001.2.3.0/24\x00/x\x00200\x000\x0012345"
|
||||
got := LabelTuple(label)
|
||||
if got.SourceTag != "" {
|
||||
t.Errorf("expected empty SourceTag for 6-field label, got %q", got.SourceTag)
|
||||
}
|
||||
if got.ASN != 12345 {
|
||||
t.Errorf("expected ASN=12345, got %d", got.ASN)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchesFilterSourceTag(t *testing.T) {
|
||||
tag := "cdn"
|
||||
cf := CompileFilter(&pb.Filter{IpngSourceTag: &tag})
|
||||
if !MatchesFilter(Tuple6{SourceTag: "cdn"}, cf) {
|
||||
t.Fatal("should match equal source_tag")
|
||||
}
|
||||
if MatchesFilter(Tuple6{SourceTag: "direct"}, cf) {
|
||||
t.Fatal("should not match different source_tag")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDimensionLabelSourceTag(t *testing.T) {
|
||||
got := DimensionLabel(Tuple6{SourceTag: "cdn"}, pb.GroupBy_SOURCE_TAG)
|
||||
if got != "cdn" {
|
||||
t.Errorf("DimensionLabel SOURCE_TAG: got %q, want %q", got, "cdn")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user