| 904 | } |
| 905 | |
| 906 | func TestNumLabelMerge(t *testing.T) { |
| 907 | for _, tc := range []struct { |
| 908 | name string |
| 909 | profs []*Profile |
| 910 | wantNumLabels []map[string][]int64 |
| 911 | wantNumUnits []map[string][]string |
| 912 | }{ |
| 913 | { |
| 914 | name: "different label units not merged", |
| 915 | profs: []*Profile{testProfile4.Copy(), testProfile5.Copy()}, |
| 916 | wantNumLabels: []map[string][]int64{ |
| 917 | { |
| 918 | "key1": {10}, |
| 919 | "key2": {30}, |
| 920 | }, |
| 921 | { |
| 922 | "key1": {10}, |
| 923 | "key2": {30}, |
| 924 | }, |
| 925 | }, |
| 926 | wantNumUnits: []map[string][]string{ |
| 927 | { |
| 928 | "key1": {"bytes"}, |
| 929 | "key2": {"bytes"}, |
| 930 | }, |
| 931 | { |
| 932 | "key1": {"kilobytes"}, |
| 933 | "key2": {"kilobytes"}, |
| 934 | }, |
| 935 | }, |
| 936 | }, |
| 937 | } { |
| 938 | t.Run(tc.name, func(t *testing.T) { |
| 939 | prof, err := Merge(tc.profs) |
| 940 | if err != nil { |
| 941 | t.Errorf("merge error: %v", err) |
| 942 | } |
| 943 | |
| 944 | if want, got := len(tc.wantNumLabels), len(prof.Sample); want != got { |
| 945 | t.Fatalf("got %d samples, want %d samples", got, want) |
| 946 | } |
| 947 | for i, wantLabels := range tc.wantNumLabels { |
| 948 | numLabels := prof.Sample[i].NumLabel |
| 949 | if !reflect.DeepEqual(wantLabels, numLabels) { |
| 950 | t.Errorf("got numeric labels %v, want %v", numLabels, wantLabels) |
| 951 | } |
| 952 | |
| 953 | wantUnits := tc.wantNumUnits[i] |
| 954 | numUnits := prof.Sample[i].NumUnit |
| 955 | if !reflect.DeepEqual(wantUnits, numUnits) { |
| 956 | t.Errorf("got numeric labels %v, want %v", numUnits, wantUnits) |
| 957 | } |
| 958 | } |
| 959 | }) |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | func TestEmptyMappingMerge(t *testing.T) { |