|
@@ -977,6 +977,59 @@ func TestHasLabel(t *testing.T) {
|
977
|
977
|
}
|
978
|
978
|
}
|
979
|
979
|
|
|
980
|
+func TestDiffBaseSample(t *testing.T) {
|
|
981
|
+ var testcases = []struct {
|
|
982
|
+ desc string
|
|
983
|
+ labels map[string][]string
|
|
984
|
+ wantDiffBaseSample bool
|
|
985
|
+ }{
|
|
986
|
+ {
|
|
987
|
+ desc: "empty label does not have label",
|
|
988
|
+ labels: map[string][]string{},
|
|
989
|
+ wantDiffBaseSample: false,
|
|
990
|
+ },
|
|
991
|
+ {
|
|
992
|
+ desc: "label with one key and value, including diff base label",
|
|
993
|
+ labels: map[string][]string{"pprof::base": {"true"}},
|
|
994
|
+ wantDiffBaseSample: true,
|
|
995
|
+ },
|
|
996
|
+ {
|
|
997
|
+ desc: "label with one key and value, not including diff base label",
|
|
998
|
+ labels: map[string][]string{"key": {"value"}},
|
|
999
|
+ wantDiffBaseSample: false,
|
|
1000
|
+ },
|
|
1001
|
+ {
|
|
1002
|
+ desc: "label with many keys and values, including diff base label",
|
|
1003
|
+ labels: map[string][]string{
|
|
1004
|
+ "pprof::base": {"value2", "true"},
|
|
1005
|
+ "key2": {"true", "value2", "value2"},
|
|
1006
|
+ "key3": {"true", "value2", "value2"},
|
|
1007
|
+ },
|
|
1008
|
+ wantDiffBaseSample: true,
|
|
1009
|
+ },
|
|
1010
|
+ {
|
|
1011
|
+ desc: "label with many keys and values, not including diff base label",
|
|
1012
|
+ labels: map[string][]string{
|
|
1013
|
+ "key1": {"value2", "value1"},
|
|
1014
|
+ "key2": {"value1", "value2", "value2"},
|
|
1015
|
+ "key3": {"value1", "value2", "value2"},
|
|
1016
|
+ },
|
|
1017
|
+ wantDiffBaseSample: false,
|
|
1018
|
+ },
|
|
1019
|
+ }
|
|
1020
|
+
|
|
1021
|
+ for _, tc := range testcases {
|
|
1022
|
+ t.Run(tc.desc, func(t *testing.T) {
|
|
1023
|
+ sample := &Sample{
|
|
1024
|
+ Label: tc.labels,
|
|
1025
|
+ }
|
|
1026
|
+ if gotHasLabel := sample.DiffBaseSample(); gotHasLabel != tc.wantDiffBaseSample {
|
|
1027
|
+ t.Errorf("sample.DiffBaseSample() got %v, want %v", gotHasLabel, tc.wantDiffBaseSample)
|
|
1028
|
+ }
|
|
1029
|
+ })
|
|
1030
|
+ }
|
|
1031
|
+}
|
|
1032
|
+
|
980
|
1033
|
func TestRemove(t *testing.T) {
|
981
|
1034
|
var testcases = []struct {
|
982
|
1035
|
desc string
|