forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impr/logcli: Added label output filters + tests (grafana#563)
* impr/logcli: Added label filters + tests * Address review * udpate readme
- Loading branch information
1 parent
cc2a54f
commit 8cda657
Showing
7 changed files
with
319 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/prometheus/prometheus/pkg/labels" | ||
) | ||
|
||
func Test_commonLabels(t *testing.T) { | ||
type args struct { | ||
lss []labels.Labels | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want labels.Labels | ||
}{ | ||
{ | ||
"Extract common labels source > target", | ||
args{ | ||
[]labels.Labels{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{bar="foo", foo="foo", baz="baz"}`)}, | ||
}, | ||
mustParseLabels(`{bar="foo"}`), | ||
}, | ||
{ | ||
"Extract common labels source > target", | ||
args{ | ||
[]labels.Labels{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{bar="foo", foo="bar", baz="baz"}`)}, | ||
}, | ||
mustParseLabels(`{foo="bar", bar="foo"}`), | ||
}, | ||
{ | ||
"Extract common labels source < target", | ||
args{ | ||
[]labels.Labels{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{bar="foo"}`)}, | ||
}, | ||
mustParseLabels(`{bar="foo"}`), | ||
}, | ||
{ | ||
"Extract common labels source < target no common", | ||
args{ | ||
[]labels.Labels{mustParseLabels(`{foo="bar", bar="foo"}`), mustParseLabels(`{fo="bar"}`)}, | ||
}, | ||
labels.Labels{}, | ||
}, | ||
{ | ||
"Extract common labels source = target no common", | ||
args{ | ||
[]labels.Labels{mustParseLabels(`{foo="bar"}`), mustParseLabels(`{fooo="bar"}`)}, | ||
}, | ||
labels.Labels{}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := commonLabels(tt.args.lss); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("commonLabels() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_subtract(t *testing.T) { | ||
type args struct { | ||
a labels.Labels | ||
b labels.Labels | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want labels.Labels | ||
}{ | ||
{ | ||
"Subtract labels source > target", | ||
args{ | ||
mustParseLabels(`{foo="bar", bar="foo"}`), | ||
mustParseLabels(`{bar="foo", foo="foo", baz="baz"}`), | ||
}, | ||
mustParseLabels(`{foo="bar"}`), | ||
}, | ||
{ | ||
"Subtract labels source < target", | ||
args{ | ||
mustParseLabels(`{foo="bar", bar="foo"}`), | ||
mustParseLabels(`{bar="foo"}`), | ||
}, | ||
mustParseLabels(`{foo="bar"}`), | ||
}, | ||
{ | ||
"Subtract labels source < target no sub", | ||
args{ | ||
mustParseLabels(`{foo="bar", bar="foo"}`), | ||
mustParseLabels(`{fo="bar"}`), | ||
}, | ||
mustParseLabels(`{bar="foo", foo="bar"}`), | ||
}, | ||
{ | ||
"Subtract labels source = target no sub", | ||
args{ | ||
mustParseLabels(`{foo="bar"}`), | ||
mustParseLabels(`{fiz="buz"}`), | ||
}, | ||
mustParseLabels(`{foo="bar"}`), | ||
}, | ||
{ | ||
"Subtract labels source > target no sub", | ||
args{ | ||
mustParseLabels(`{foo="bar"}`), | ||
mustParseLabels(`{fiz="buz", foo="baz"}`), | ||
}, | ||
mustParseLabels(`{foo="bar"}`), | ||
}, | ||
{ | ||
"Subtract labels source > target no sub", | ||
args{ | ||
mustParseLabels(`{a="b", foo="bar", baz="baz", fizz="fizz"}`), | ||
mustParseLabels(`{foo="bar", baz="baz", buzz="buzz", fizz="fizz"}`), | ||
}, | ||
mustParseLabels(`{a="b"}`), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := subtract(tt.args.a, tt.args.b); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("subtract() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.