Skip to content

Commit 9f9becd

Browse files
committed
Test object metric with oneOf structure in the samples
This requires a glean_parser update to actually work.
1 parent 164054a commit 9f9becd

File tree

7 files changed

+126
-0
lines changed

7 files changed

+126
-0
lines changed

samples/android/app/metrics.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ party:
192192
notification_emails:
193193
194194
expires: never
195+
send_in_pings:
196+
- sample
195197
structure:
196198
type: array
197199
items:
@@ -218,7 +220,35 @@ party:
218220
data_sensitivity:
219221
- technical
220222
expires: never
223+
send_in_pings:
224+
- sample
221225
structure:
222226
type: array
223227
items:
224228
type: string
229+
230+
chooser:
231+
type: object
232+
description: |
233+
Array of key-value elements
234+
bugs:
235+
- https://bugzilla.mozilla.org/123456789
236+
data_reviews:
237+
- http://example.com/reviews
238+
notification_emails:
239+
240+
expires: never
241+
send_in_pings:
242+
- sample
243+
structure:
244+
type: array
245+
items:
246+
type: object
247+
properties:
248+
key:
249+
type: string
250+
value:
251+
oneOf:
252+
- type: string
253+
- type: number
254+
- type: boolean

samples/android/app/src/main/java/org/mozilla/samples/gleancore/MainActivity.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ open class MainActivity : AppCompatActivity() {
5454
balloons.add(Party.BalloonsObjectItem(colour = "green"))
5555
Party.balloons.set(balloons)
5656

57+
val ch = Party.ChooserObject()
58+
var f = Party.ChooserObjectItem(key = "fortytwo", value = Party.ChooserObjectItemValueEnum.Number(42))
59+
ch.add(f)
60+
f = Party.ChooserObjectItem(key = "to-be", value = Party.ChooserObjectItemValueEnum.Boolean(false))
61+
ch.add(f)
62+
Party.chooser.set(ch)
63+
5764
val animals = Party.AnimalsObject()
5865
animals.add("Dog")
5966
animals.add("Cat")

samples/ios/app/glean-sample-app/ViewController.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class ViewController: UIViewController {
7070
animals.append("Cat")
7171
Party.animals.set(animals)
7272

73+
var ch: Party.ChooserObject = []
74+
var f = Party.ChooserObjectItem(key: "fortytwo", value: .number(42))
75+
ch.append(f)
76+
f = Party.ChooserObjectItem(key: "to-be", value: .boolean(false))
77+
ch.append(f)
78+
Party.chooser.set(ch)
79+
7380
// This is referencing the event ping named 'click' from the metrics.yaml file. In
7481
// order to illustrate adding extra information to the event, it is also adding to the
7582
// 'extras' field a dictionary of values. Note that the dictionary keys must be

samples/ios/app/glean-sample-appUITests/ViewControllerTest.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class ViewControllerTest: XCTestCase {
4949
let objects = metrics["object"] as! [String: Any]
5050
let balloons = objects["party.balloons"] as! [Any]
5151
XCTAssertEqual(balloons.count, 2)
52+
53+
let expectedChooser: [[String: AnyHashable]] = [
54+
["key": "fortytwo", "value": 42],
55+
["key": "to-be", "value": false]
56+
]
57+
58+
let chooser = objects["party.chooser"] as! [[String: AnyHashable]]
59+
XCTAssertEqual(expectedChooser, chooser)
5260
}
5361

5462
func testViewControllerInteraction() {

samples/ios/app/metrics.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,29 @@ party:
215215
type: array
216216
items:
217217
type: string
218+
219+
chooser:
220+
type: object
221+
description: |
222+
Array of key-value elements
223+
bugs:
224+
- https://bugzilla.mozilla.org/123456789
225+
data_reviews:
226+
- http://example.com/reviews
227+
notification_emails:
228+
229+
expires: never
230+
send_in_pings:
231+
- sample
232+
structure:
233+
type: array
234+
items:
235+
type: object
236+
properties:
237+
key:
238+
type: string
239+
value:
240+
oneOf:
241+
- type: string
242+
- type: number
243+
- type: boolean

samples/rust/metrics.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,30 @@ party:
146146
items:
147147
type: string
148148

149+
chooser:
150+
type: object
151+
description: |
152+
Array of key-value elements
153+
bugs:
154+
- https://bugzilla.mozilla.org/123456789
155+
data_reviews:
156+
- http://example.com/reviews
157+
notification_emails:
158+
159+
expires: never
160+
structure:
161+
type: array
162+
items:
163+
type: object
164+
properties:
165+
key:
166+
type: string
167+
value:
168+
oneOf:
169+
- type: string
170+
- type: number
171+
- type: boolean
172+
149173
glean.attribution:
150174
ext:
151175
type: object

samples/rust/src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ fn main() {
132132
]);
133133
glean_metrics::party::balloons.set(balloons);
134134

135+
use glean_metrics::party::{ChooserObject, ChooserObjectItem, ChooserObjectItemValueEnum};
136+
let mut ch = ChooserObject::new();
137+
let it = ChooserObjectItem {
138+
key: Some("fortytwo".to_string()),
139+
value: Some(ChooserObjectItemValueEnum::Number(42)),
140+
};
141+
ch.push(it);
142+
let it = ChooserObjectItem {
143+
key: Some("to-be".to_string()),
144+
value: Some(ChooserObjectItemValueEnum::Boolean(false)),
145+
};
146+
ch.push(it);
147+
glean_metrics::party::chooser.set(ch);
148+
149+
let exp_chooser = serde_json::json!([
150+
{ "key": "fortytwo", "value": 42 },
151+
{ "key": "to-be", "value": false },
152+
]);
153+
154+
assert_eq!(
155+
Some(exp_chooser),
156+
glean_metrics::party::chooser.test_get_value(None)
157+
);
158+
135159
glean_metrics::test_dual_labeled::static_static
136160
.get("key1", "category1")
137161
.add(1);

0 commit comments

Comments
 (0)