|
4 | 4 | "fmt"
|
5 | 5 | "os"
|
6 | 6 | "path/filepath"
|
| 7 | + "strings" |
7 | 8 |
|
8 | 9 | . "github.com/onsi/ginkgo/v2"
|
9 | 10 | . "github.com/onsi/gomega"
|
@@ -204,64 +205,166 @@ OdoSettings:
|
204 | 205 | })
|
205 | 206 | })
|
206 | 207 |
|
207 |
| - When("Telemetry is enabled in preferences", func() { |
| 208 | + When("telemetry is enabled", func() { |
| 209 | + var prefClient preference.Client |
| 210 | + |
208 | 211 | BeforeEach(func() {
|
209 |
| - prefClient := helper.EnableTelemetryDebug() |
210 |
| - err := prefClient.SetConfiguration(preference.ConsentTelemetrySetting, "true") |
211 |
| - Expect(err).ShouldNot(HaveOccurred()) |
212 |
| - Expect(os.Unsetenv(segment.TrackingConsentEnv)).NotTo(HaveOccurred()) |
| 212 | + prefClient = helper.EnableTelemetryDebug() |
213 | 213 | })
|
214 | 214 |
|
215 | 215 | AfterEach(func() {
|
216 | 216 | helper.ResetTelemetry()
|
217 | 217 | })
|
218 | 218 |
|
219 |
| - When("setting ConsentTelemetry to false", func() { |
220 |
| - BeforeEach(func() { |
221 |
| - helper.Cmd("odo", "preference", "set", "ConsentTelemetry", "false", "--force").ShouldPass() |
| 219 | + for _, tt := range []struct { |
| 220 | + prefParam string |
| 221 | + value string |
| 222 | + differentValueIfAnonymized string |
| 223 | + clearText bool |
| 224 | + }{ |
| 225 | + {"ConsentTelemetry", "true", "", true}, |
| 226 | + {"Ephemeral", "false", "", true}, |
| 227 | + {"UpdateNotification", "true", "", true}, |
| 228 | + {"PushTimeout", "1m", "", true}, |
| 229 | + {"RegistryCacheTime", "2s", "", true}, |
| 230 | + {"Timeout", "30s", "", true}, |
| 231 | + {"ImageRegistry", "quay.io/some-org", "ghcr.io/my-org", false}, |
| 232 | + } { |
| 233 | + tt := tt |
| 234 | + form := "hashed" |
| 235 | + if tt.clearText { |
| 236 | + form = "plain" |
| 237 | + } |
| 238 | + |
| 239 | + When("unsetting value for preference "+tt.prefParam, func() { |
| 240 | + BeforeEach(func() { |
| 241 | + helper.Cmd("odo", "preference", "unset", tt.prefParam, "--force").ShouldPass() |
| 242 | + }) |
| 243 | + |
| 244 | + It("should track parameter that is unset without any value", func() { |
| 245 | + helper.Cmd("odo", "preference", "unset", tt.prefParam, "--force").ShouldPass() |
| 246 | + td := helper.GetTelemetryDebugData() |
| 247 | + Expect(td.Event).To(ContainSubstring("odo preference unset")) |
| 248 | + Expect(td.Properties.Success).To(BeTrue()) |
| 249 | + Expect(td.Properties.Error).To(BeEmpty()) |
| 250 | + Expect(td.Properties.ErrorType).To(BeEmpty()) |
| 251 | + Expect(td.Properties.CmdProperties[segmentContext.Flags]).To(Equal("force")) |
| 252 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceParameter]).To(Equal(strings.ToLower(tt.prefParam))) |
| 253 | + valueRecorded, present := td.Properties.CmdProperties[segmentContext.PreferenceValue] |
| 254 | + Expect(present).To(BeFalse(), fmt.Sprintf("no value should be recorded for preference %q, fot %q", tt.prefParam, valueRecorded)) |
| 255 | + }) |
222 | 256 | })
|
223 | 257 |
|
224 |
| - // https://github.com/redhat-developer/odo/issues/6790 |
225 |
| - It("should record the odo-preference-set command in telemetry", func() { |
226 |
| - td := helper.GetTelemetryDebugData() |
227 |
| - Expect(td.Event).To(ContainSubstring("odo preference set")) |
228 |
| - Expect(td.Properties.Success).To(BeTrue()) |
229 |
| - Expect(td.Properties.Error).To(BeEmpty()) |
230 |
| - Expect(td.Properties.ErrorType).To(BeEmpty()) |
231 |
| - Expect(td.Properties.CmdProperties[segmentContext.Flags]).To(Equal("force")) |
232 |
| - Expect(td.Properties.CmdProperties[segmentContext.PreviousTelemetryStatus]).To(BeTrue()) |
233 |
| - Expect(td.Properties.CmdProperties[segmentContext.TelemetryStatus]).To(BeFalse()) |
| 258 | + When("setting value for preference "+tt.prefParam, func() { |
| 259 | + BeforeEach(func() { |
| 260 | + if !tt.clearText { |
| 261 | + Expect(tt.differentValueIfAnonymized).ShouldNot(Equal(tt.value), |
| 262 | + "test not written as expected. Values should be different for preference parameters declared as anonymized.") |
| 263 | + } |
| 264 | + helper.Cmd("odo", "preference", "set", tt.prefParam, tt.value, "--force").ShouldPass() |
| 265 | + }) |
| 266 | + |
| 267 | + It(fmt.Sprintf("should track parameter that is set along with its %s value", form), func() { |
| 268 | + td := helper.GetTelemetryDebugData() |
| 269 | + Expect(td.Event).To(ContainSubstring("odo preference set")) |
| 270 | + Expect(td.Properties.Success).To(BeTrue()) |
| 271 | + Expect(td.Properties.Error).To(BeEmpty()) |
| 272 | + Expect(td.Properties.ErrorType).To(BeEmpty()) |
| 273 | + Expect(td.Properties.CmdProperties[segmentContext.Flags]).To(Equal("force")) |
| 274 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceParameter]).To(Equal(strings.ToLower(tt.prefParam))) |
| 275 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).ShouldNot(BeEmpty()) |
| 276 | + if tt.clearText { |
| 277 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).Should(Equal(tt.value)) |
| 278 | + } else { |
| 279 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).ShouldNot(Equal(tt.value)) |
| 280 | + } |
| 281 | + }) |
| 282 | + |
| 283 | + if !tt.clearText { |
| 284 | + It("should anonymize values set such that same strings have same hash", func() { |
| 285 | + td := helper.GetTelemetryDebugData() |
| 286 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).ShouldNot(BeEmpty()) |
| 287 | + pref1Val, ok := td.Properties.CmdProperties[segmentContext.PreferenceValue].(string) |
| 288 | + Expect(ok).To(BeTrue(), fmt.Sprintf("value recorded in telemetry for preference %q is expected to be a string", tt.prefParam)) |
| 289 | + |
| 290 | + helper.ClearTelemetryFile() |
| 291 | + |
| 292 | + helper.Cmd("odo", "preference", "set", tt.prefParam, tt.value, "--force").ShouldPass() |
| 293 | + td = helper.GetTelemetryDebugData() |
| 294 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).ShouldNot(BeEmpty()) |
| 295 | + pref2Val, ok := td.Properties.CmdProperties[segmentContext.PreferenceValue].(string) |
| 296 | + Expect(ok).To(BeTrue(), fmt.Sprintf("value recorded in telemetry for preference %q is expected to be a string", tt.prefParam)) |
| 297 | + |
| 298 | + Expect(pref1Val).To(Equal(pref2Val)) |
| 299 | + }) |
| 300 | + |
| 301 | + It("should anonymize values set such that different strings will not have same hash", func() { |
| 302 | + td := helper.GetTelemetryDebugData() |
| 303 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).ShouldNot(BeEmpty()) |
| 304 | + pref1Val, ok := td.Properties.CmdProperties[segmentContext.PreferenceValue].(string) |
| 305 | + Expect(ok).To(BeTrue(), fmt.Sprintf("value recorded in telemetry for preference %q is expected to be a string", tt.prefParam)) |
| 306 | + |
| 307 | + helper.ClearTelemetryFile() |
| 308 | + |
| 309 | + helper.Cmd("odo", "preference", "set", tt.prefParam, tt.differentValueIfAnonymized, "--force").ShouldPass() |
| 310 | + td = helper.GetTelemetryDebugData() |
| 311 | + Expect(td.Properties.CmdProperties[segmentContext.PreferenceValue]).ShouldNot(BeEmpty()) |
| 312 | + pref2Val, ok := td.Properties.CmdProperties[segmentContext.PreferenceValue].(string) |
| 313 | + Expect(ok).To(BeTrue(), fmt.Sprintf("value recorded in telemetry for preference %q is expected to be a string", tt.prefParam)) |
| 314 | + |
| 315 | + Expect(pref1Val).ToNot(Equal(pref2Val)) |
| 316 | + }) |
| 317 | + } |
234 | 318 | })
|
235 |
| - }) |
236 |
| - }) |
| 319 | + } |
237 | 320 |
|
238 |
| - When("Telemetry is disabled in preferences", func() { |
239 |
| - BeforeEach(func() { |
240 |
| - prefClient := helper.EnableTelemetryDebug() |
241 |
| - err := prefClient.SetConfiguration(preference.ConsentTelemetrySetting, "false") |
242 |
| - Expect(err).ShouldNot(HaveOccurred()) |
243 |
| - Expect(os.Unsetenv(segment.TrackingConsentEnv)).NotTo(HaveOccurred()) |
244 |
| - }) |
| 321 | + When("telemetry is enabled in preferences", func() { |
| 322 | + BeforeEach(func() { |
| 323 | + Expect(os.Unsetenv(segment.TrackingConsentEnv)).NotTo(HaveOccurred()) |
| 324 | + Expect(prefClient.SetConfiguration(preference.ConsentTelemetrySetting, "true")).ShouldNot(HaveOccurred()) |
| 325 | + }) |
245 | 326 |
|
246 |
| - AfterEach(func() { |
247 |
| - helper.ResetTelemetry() |
| 327 | + When("setting ConsentTelemetry to false", func() { |
| 328 | + BeforeEach(func() { |
| 329 | + helper.Cmd("odo", "preference", "set", "ConsentTelemetry", "false", "--force").ShouldPass() |
| 330 | + }) |
| 331 | + |
| 332 | + // https://github.com/redhat-developer/odo/issues/6790 |
| 333 | + It("should record the odo-preference-set command in telemetry", func() { |
| 334 | + td := helper.GetTelemetryDebugData() |
| 335 | + Expect(td.Event).To(ContainSubstring("odo preference set")) |
| 336 | + Expect(td.Properties.Success).To(BeTrue()) |
| 337 | + Expect(td.Properties.Error).To(BeEmpty()) |
| 338 | + Expect(td.Properties.ErrorType).To(BeEmpty()) |
| 339 | + Expect(td.Properties.CmdProperties[segmentContext.Flags]).To(Equal("force")) |
| 340 | + Expect(td.Properties.CmdProperties[segmentContext.PreviousTelemetryStatus]).To(BeTrue()) |
| 341 | + Expect(td.Properties.CmdProperties[segmentContext.TelemetryStatus]).To(BeFalse()) |
| 342 | + }) |
| 343 | + }) |
248 | 344 | })
|
249 | 345 |
|
250 |
| - When("setting ConsentTelemetry to true", func() { |
| 346 | + When("Telemetry is disabled in preferences", func() { |
251 | 347 | BeforeEach(func() {
|
252 |
| - helper.Cmd("odo", "preference", "set", "ConsentTelemetry", "true", "--force").ShouldPass() |
| 348 | + Expect(os.Unsetenv(segment.TrackingConsentEnv)).NotTo(HaveOccurred()) |
| 349 | + Expect(prefClient.SetConfiguration(preference.ConsentTelemetrySetting, "false")).ShouldNot(HaveOccurred()) |
253 | 350 | })
|
254 | 351 |
|
255 |
| - // https://github.com/redhat-developer/odo/issues/6790 |
256 |
| - It("should record the odo-preference-set command in telemetry", func() { |
257 |
| - td := helper.GetTelemetryDebugData() |
258 |
| - Expect(td.Event).To(ContainSubstring("odo preference set")) |
259 |
| - Expect(td.Properties.Success).To(BeTrue()) |
260 |
| - Expect(td.Properties.Error).To(BeEmpty()) |
261 |
| - Expect(td.Properties.ErrorType).To(BeEmpty()) |
262 |
| - Expect(td.Properties.CmdProperties[segmentContext.Flags]).To(Equal("force")) |
263 |
| - Expect(td.Properties.CmdProperties[segmentContext.PreviousTelemetryStatus]).To(BeFalse()) |
264 |
| - Expect(td.Properties.CmdProperties[segmentContext.TelemetryStatus]).To(BeTrue()) |
| 352 | + When("setting ConsentTelemetry to true", func() { |
| 353 | + BeforeEach(func() { |
| 354 | + helper.Cmd("odo", "preference", "set", "ConsentTelemetry", "true", "--force").ShouldPass() |
| 355 | + }) |
| 356 | + |
| 357 | + // https://github.com/redhat-developer/odo/issues/6790 |
| 358 | + It("should record the odo-preference-set command in telemetry", func() { |
| 359 | + td := helper.GetTelemetryDebugData() |
| 360 | + Expect(td.Event).To(ContainSubstring("odo preference set")) |
| 361 | + Expect(td.Properties.Success).To(BeTrue()) |
| 362 | + Expect(td.Properties.Error).To(BeEmpty()) |
| 363 | + Expect(td.Properties.ErrorType).To(BeEmpty()) |
| 364 | + Expect(td.Properties.CmdProperties[segmentContext.Flags]).To(Equal("force")) |
| 365 | + Expect(td.Properties.CmdProperties[segmentContext.PreviousTelemetryStatus]).To(BeFalse()) |
| 366 | + Expect(td.Properties.CmdProperties[segmentContext.TelemetryStatus]).To(BeTrue()) |
| 367 | + }) |
265 | 368 | })
|
266 | 369 | })
|
267 | 370 | })
|
|
0 commit comments