@@ -86,48 +86,67 @@ func TestStringSliceAsHeader(t *testing.T) {
86
86
require .NoError (t , err )
87
87
}
88
88
89
- func initializedFn () (* storage.ArchiveStorage , error ) {
90
- return & storage.ArchiveStorage {
91
- Reader : & spanstoremocks.Reader {},
92
- Writer : & spanstoremocks.Writer {},
93
- }, nil
94
- }
95
-
96
- func uninitializedFn () (* storage.ArchiveStorage , error ) {
97
- return nil , nil
98
- }
99
-
100
89
func TestBuildQueryServiceOptions (t * testing.T ) {
101
- v , _ := config .Viperize (AddFlags )
102
- qOpts , err := new (QueryOptions ).InitFromViper (v , zap .NewNop ())
103
- require .NoError (t , err )
104
- assert .NotNil (t , qOpts )
105
-
106
- qSvcOpts , v2qSvcOpts := qOpts .BuildQueryServiceOptions (initializedFn , zap .NewNop ())
107
- assert .NotNil (t , qSvcOpts )
108
- assert .NotNil (t , qSvcOpts .ArchiveSpanReader )
109
- assert .NotNil (t , qSvcOpts .ArchiveSpanWriter )
110
- assert .NotNil (t , v2qSvcOpts .ArchiveTraceReader )
111
- assert .NotNil (t , v2qSvcOpts .ArchiveTraceWriter )
112
- assert .Equal (t , defaultMaxClockSkewAdjust , qSvcOpts .MaxClockSkewAdjust )
113
- }
114
-
115
- func TestBuildQueryServiceOptions_NoArchiveStorage (t * testing.T ) {
116
- v , _ := config .Viperize (AddFlags )
117
- qOpts , err := new (QueryOptions ).InitFromViper (v , zap .NewNop ())
118
- require .NoError (t , err )
119
- assert .NotNil (t , qOpts )
90
+ tests := []struct {
91
+ name string
92
+ initFn func () (* storage.ArchiveStorage , error )
93
+ expectNilStorage bool
94
+ expectedLogEntry string
95
+ }{
96
+ {
97
+ name : "successful initialization" ,
98
+ initFn : func () (* storage.ArchiveStorage , error ) {
99
+ return & storage.ArchiveStorage {
100
+ Reader : & spanstoremocks.Reader {},
101
+ Writer : & spanstoremocks.Writer {},
102
+ }, nil
103
+ },
104
+ expectNilStorage : false ,
105
+ },
106
+ {
107
+ name : "error initializing archive storage" ,
108
+ initFn : func () (* storage.ArchiveStorage , error ) {
109
+ return nil , assert .AnError
110
+ },
111
+ expectNilStorage : true ,
112
+ expectedLogEntry : "Received an error when trying to initialize archive storage" ,
113
+ },
114
+ {
115
+ name : "no archive storage" ,
116
+ initFn : func () (* storage.ArchiveStorage , error ) {
117
+ return nil , nil
118
+ },
119
+ expectNilStorage : true ,
120
+ expectedLogEntry : "Archive storage not initialized" ,
121
+ },
122
+ }
120
123
121
- logger , logBuf := testutils .NewLogger ()
122
- qSvcOpts , v2qSvcOpts := qOpts .BuildQueryServiceOptions (uninitializedFn , logger )
123
- assert .NotNil (t , qSvcOpts )
124
- assert .Nil (t , qSvcOpts .ArchiveSpanReader )
125
- assert .Nil (t , qSvcOpts .ArchiveSpanWriter )
126
- assert .Nil (t , v2qSvcOpts .ArchiveTraceReader )
127
- assert .Nil (t , v2qSvcOpts .ArchiveTraceWriter )
128
- assert .Equal (t , defaultMaxClockSkewAdjust , qSvcOpts .MaxClockSkewAdjust )
129
-
130
- require .Contains (t , logBuf .String (), "Archive storage not initialized" )
124
+ for _ , test := range tests {
125
+ t .Run (test .name , func (t * testing.T ) {
126
+ v , _ := config .Viperize (AddFlags )
127
+ qOpts , err := new (QueryOptions ).InitFromViper (v , zap .NewNop ())
128
+ require .NoError (t , err )
129
+ require .NotNil (t , qOpts )
130
+
131
+ logger , logBuf := testutils .NewLogger ()
132
+ qSvcOpts , v2qSvcOpts := qOpts .BuildQueryServiceOptions (test .initFn , logger )
133
+ require .Equal (t , defaultMaxClockSkewAdjust , qSvcOpts .MaxClockSkewAdjust )
134
+
135
+ if test .expectNilStorage {
136
+ require .Nil (t , qSvcOpts .ArchiveSpanReader )
137
+ require .Nil (t , qSvcOpts .ArchiveSpanWriter )
138
+ require .Nil (t , v2qSvcOpts .ArchiveTraceReader )
139
+ require .Nil (t , v2qSvcOpts .ArchiveTraceWriter )
140
+ } else {
141
+ require .NotNil (t , qSvcOpts .ArchiveSpanReader )
142
+ require .NotNil (t , qSvcOpts .ArchiveSpanWriter )
143
+ require .NotNil (t , v2qSvcOpts .ArchiveTraceReader )
144
+ require .NotNil (t , v2qSvcOpts .ArchiveTraceWriter )
145
+ }
146
+
147
+ require .Contains (t , logBuf .String (), test .expectedLogEntry )
148
+ })
149
+ }
131
150
}
132
151
133
152
func TestQueryOptionsPortAllocationFromFlags (t * testing.T ) {
0 commit comments