1
+ // +build !integration
2
+
3
+ package main
4
+
5
+ import (
6
+ "testing"
7
+ . "gopkg.in/check.v1"
8
+
9
+ "github.com/blang/semver"
10
+ )
11
+
12
+ // Hook up gocheck into the "go test" runner.
13
+ func Test (t * testing.T ) { TestingT (t ) }
14
+
15
+ type FunctionalSuite struct {
16
+ e * Exporter
17
+ }
18
+
19
+ var _ = Suite (& FunctionalSuite {})
20
+
21
+ func (s * FunctionalSuite ) SetUpSuite (c * C ) {
22
+
23
+ }
24
+
25
+ func (s * FunctionalSuite ) TestSemanticVersionColumnDiscard (c * C ) {
26
+ testMetricMap := map [string ]map [string ]ColumnMapping {
27
+ "test_namespace" : map [string ]ColumnMapping {
28
+ "metric_which_stays" : {COUNTER , "This metric should not be eliminated" , nil , nil },
29
+ "metric_which_discards" : {COUNTER , "This metric should be forced to DISCARD" , nil , nil },
30
+ },
31
+ }
32
+
33
+ {
34
+ // No metrics should be eliminated
35
+ resultMap := makeDescMap (semver .MustParse ("0.0.1" ), testMetricMap )
36
+ c .Check (
37
+ resultMap ["test_namespace" ].columnMappings ["metric_which_stays" ].discard ,
38
+ Equals ,
39
+ false ,
40
+ )
41
+ c .Check (
42
+ resultMap ["test_namespace" ].columnMappings ["metric_which_discards" ].discard ,
43
+ Equals ,
44
+ false ,
45
+ )
46
+ }
47
+
48
+ {
49
+ // Update the map so the discard metric should be eliminated
50
+ discardable_metric := testMetricMap ["test_namespace" ]["metric_which_discards" ]
51
+ discardable_metric .supportedVersions = semver .MustParseRange (">0.0.1" )
52
+ testMetricMap ["test_namespace" ]["metric_which_discards" ] = discardable_metric
53
+
54
+ // Discard metric should be discarded
55
+ resultMap := makeDescMap (semver .MustParse ("0.0.1" ), testMetricMap )
56
+ c .Check (
57
+ resultMap ["test_namespace" ].columnMappings ["metric_which_stays" ].discard ,
58
+ Equals ,
59
+ false ,
60
+ )
61
+ c .Check (
62
+ resultMap ["test_namespace" ].columnMappings ["metric_which_discards" ].discard ,
63
+ Equals ,
64
+ true ,
65
+ )
66
+ }
67
+
68
+ {
69
+ // Update the map so the discard metric should be kept but has a version
70
+ discardable_metric := testMetricMap ["test_namespace" ]["metric_which_discards" ]
71
+ discardable_metric .supportedVersions = semver .MustParseRange (">0.0.1" )
72
+ testMetricMap ["test_namespace" ]["metric_which_discards" ] = discardable_metric
73
+
74
+ // Discard metric should be discarded
75
+ resultMap := makeDescMap (semver .MustParse ("0.0.2" ), testMetricMap )
76
+ c .Check (
77
+ resultMap ["test_namespace" ].columnMappings ["metric_which_stays" ].discard ,
78
+ Equals ,
79
+ false ,
80
+ )
81
+ c .Check (
82
+ resultMap ["test_namespace" ].columnMappings ["metric_which_discards" ].discard ,
83
+ Equals ,
84
+ false ,
85
+ )
86
+ }
87
+ }
0 commit comments