github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/query/storage/m3/storagemetadata/attributes_test.go (about) 1 // Copyright (c) 2022 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 storagemetadata 22 23 import ( 24 "testing" 25 "time" 26 27 "github.com/stretchr/testify/assert" 28 ) 29 30 func TestAttributes_CombinedWith(t *testing.T) { 31 tests := []struct { 32 name string 33 given Attributes 34 with Attributes 35 want Attributes 36 }{ 37 { 38 name: "aggregated with unaggregated", 39 given: Attributes{ 40 MetricsType: AggregatedMetricsType, 41 Retention: 12 * time.Hour, 42 Resolution: 5 * time.Minute, 43 }, 44 with: Attributes{ 45 MetricsType: UnaggregatedMetricsType, 46 Retention: 3 * time.Hour, 47 Resolution: time.Minute, 48 }, 49 want: Attributes{ 50 MetricsType: AggregatedMetricsType, 51 Retention: 12 * time.Hour, 52 Resolution: 5 * time.Minute, 53 }, 54 }, 55 56 { 57 name: "unaggregated with aggregated", 58 given: Attributes{ 59 MetricsType: UnaggregatedMetricsType, 60 Retention: 3 * time.Hour, 61 Resolution: time.Minute, 62 }, 63 with: Attributes{ 64 MetricsType: AggregatedMetricsType, 65 Retention: 12 * time.Hour, 66 Resolution: 5 * time.Minute, 67 }, 68 want: Attributes{ 69 MetricsType: AggregatedMetricsType, 70 Retention: 12 * time.Hour, 71 Resolution: 5 * time.Minute, 72 }, 73 }, 74 75 { 76 name: "aggregated with aggregated", 77 given: Attributes{ 78 MetricsType: AggregatedMetricsType, 79 Retention: 12 * time.Hour, 80 Resolution: 5 * time.Minute, 81 }, 82 with: Attributes{ 83 MetricsType: AggregatedMetricsType, 84 Retention: 3 * time.Hour, 85 Resolution: 10 * time.Minute, 86 }, 87 want: Attributes{ 88 MetricsType: AggregatedMetricsType, 89 Retention: 12 * time.Hour, 90 Resolution: 10 * time.Minute, 91 }, 92 }, 93 94 { 95 name: "unaggregated with unaggregated", 96 given: Attributes{ 97 MetricsType: UnaggregatedMetricsType, 98 Retention: 3 * time.Hour, 99 Resolution: 10 * time.Minute, 100 }, 101 with: Attributes{ 102 MetricsType: UnaggregatedMetricsType, 103 Retention: 12 * time.Hour, 104 Resolution: 5 * time.Minute, 105 }, 106 want: Attributes{ 107 MetricsType: UnaggregatedMetricsType, 108 Retention: 12 * time.Hour, 109 Resolution: 10 * time.Minute, 110 }, 111 }, 112 } 113 for _, tt := range tests { 114 t.Run(tt.name, func(t *testing.T) { 115 assert.Equal(t, tt.want, tt.given.CombinedWith(tt.with), "CombinedWith(%v)") 116 }) 117 } 118 }