github.com/m3db/m3@v1.5.0/src/metrics/rules/view/mapping_test.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package view 22 23 import ( 24 "testing" 25 "time" 26 27 "github.com/m3db/m3/src/metrics/aggregation" 28 "github.com/m3db/m3/src/metrics/policy" 29 "github.com/m3db/m3/src/query/models" 30 xtime "github.com/m3db/m3/src/x/time" 31 32 "github.com/stretchr/testify/require" 33 ) 34 35 func TestMappingRuleEqual(t *testing.T) { 36 rule1 := MappingRule{ 37 ID: "mr_id", 38 Name: "mr_name", 39 CutoverMillis: 1234, 40 Filter: "filter", 41 AggregationID: aggregation.MustCompressTypes(aggregation.Sum), 42 StoragePolicies: policy.StoragePolicies{ 43 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 44 }, 45 LastUpdatedAtMillis: 1234, 46 LastUpdatedBy: "john", 47 Tags: []models.Tag{{Name: []byte("name_1"), Value: []byte("val_1")}}, 48 } 49 rule2 := MappingRule{ 50 ID: "mr_id", 51 Name: "mr_name", 52 CutoverMillis: 1234, 53 Filter: "filter", 54 AggregationID: aggregation.MustCompressTypes(aggregation.Sum), 55 StoragePolicies: policy.StoragePolicies{ 56 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 57 }, 58 LastUpdatedAtMillis: 1234, 59 LastUpdatedBy: "john", 60 Tags: []models.Tag{{Name: []byte("name_1"), Value: []byte("val_1")}}, 61 } 62 require.True(t, rule1.Equal(&rule2)) 63 require.True(t, rule2.Equal(&rule1)) 64 } 65 66 func TestMappingRuleNotEqual(t *testing.T) { 67 rules := []MappingRule{ 68 { 69 ID: "mr", 70 Name: "foo", 71 Filter: "filter", 72 AggregationID: aggregation.MustCompressTypes(aggregation.Sum), 73 StoragePolicies: policy.StoragePolicies{ 74 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 75 }, 76 }, 77 { 78 ID: "mr", 79 Name: "foo", 80 Filter: "filter", 81 AggregationID: aggregation.DefaultID, 82 StoragePolicies: policy.StoragePolicies{ 83 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 84 }, 85 }, 86 { 87 ID: "mr", 88 Name: "foo", 89 Filter: "filter", 90 AggregationID: aggregation.DefaultID, 91 StoragePolicies: policy.StoragePolicies{ 92 policy.NewStoragePolicy(time.Minute, xtime.Minute, time.Hour), 93 }, 94 }, 95 { 96 ID: "mr", 97 Name: "bar", 98 Filter: "filter", 99 AggregationID: aggregation.DefaultID, 100 StoragePolicies: policy.StoragePolicies{ 101 policy.NewStoragePolicy(time.Minute, xtime.Minute, time.Hour), 102 }, 103 }, 104 { 105 ID: "mr", 106 Name: "bar", 107 Filter: "filter2", 108 AggregationID: aggregation.DefaultID, 109 StoragePolicies: policy.StoragePolicies{ 110 policy.NewStoragePolicy(time.Minute, xtime.Minute, time.Hour), 111 }, 112 }, 113 { 114 ID: "mr", 115 Name: "foo", 116 Filter: "filter", 117 AggregationID: aggregation.MustCompressTypes(aggregation.Sum), 118 StoragePolicies: policy.StoragePolicies{ 119 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 120 }, 121 DropPolicy: policy.DropMust, 122 }, 123 { 124 ID: "mr", 125 Name: "foo", 126 Filter: "filter", 127 AggregationID: aggregation.MustCompressTypes(aggregation.Sum), 128 StoragePolicies: policy.StoragePolicies{ 129 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 130 }, 131 DropPolicy: policy.DropIfOnlyMatch, 132 }, 133 { 134 ID: "mr", 135 Name: "foo", 136 Filter: "filter", 137 AggregationID: aggregation.MustCompressTypes(aggregation.Sum), 138 StoragePolicies: policy.StoragePolicies{ 139 policy.NewStoragePolicy(10*time.Second, xtime.Second, time.Hour), 140 }, 141 Tags: []models.Tag{{Name: []byte("name_1"), Value: []byte("val_1")}}, 142 }, 143 } 144 for i := 0; i < len(rules); i++ { 145 for j := i + 1; j < len(rules); j++ { 146 require.False(t, rules[i].Equal(&rules[j])) 147 } 148 } 149 } 150 151 func TestMappingRuleEqualNilCases(t *testing.T) { 152 var ( 153 mr1 *MappingRule 154 mr2 MappingRule 155 ) 156 require.True(t, mr1.Equal(nil)) 157 require.False(t, mr2.Equal(mr1)) 158 }