@@ -56,6 +56,18 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
5656 "from": "100",
5757 "to": "200"
5858 }
59+ },
60+ {
61+ "refId": "Q",
62+ "datasource": {
63+ "type": "prometheus",
64+ "uid": "u-i-d"
65+ },
66+ "expr": "42",
67+ "_timeRange": {
68+ "from": "10",
69+ "to": "20"
70+ }
5971 }
6072 ],
6173 "from": "1692624667389",
@@ -67,7 +79,7 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
6779 require .NoError (t , err )
6880
6981 t .Run ("verify raw unmarshal" , func (t * testing.T ) {
70- require .Len (t , req .Queries , 2 )
82+ require .Len (t , req .Queries , 3 )
7183 require .Equal (t , "b1808c48-9fc9-4045-82d7-081781f8a553" , req .Queries [0 ].Datasource .UID )
7284 require .Equal (t , "spreadsheetID" , req .Queries [0 ].GetString ("spreadsheet" ))
7385
@@ -84,21 +96,42 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
8496 require .Equal (t , int64 (10 ), req .Queries [1 ].MaxDataPoints ) // input was a string
8597
8698 // The second query has an explicit time range, and legacy datasource name
99+ require .NotNil (t , req .Queries [1 ].TimeRange )
100+ require .Equal (t , "100" , req .Queries [1 ].TimeRange .From )
101+ require .Equal (t , "200" , req .Queries [1 ].TimeRange .To )
87102 out , err = json .MarshalIndent (req .Queries [1 ], "" , " " )
88103 require .NoError (t , err )
89- // fmt.Printf("%s\n", string(out))
90104 require .JSONEq (t , `{
91105 "datasource": {
92106 "type": "", ` /* NOTE! this implies legacy naming */ + `
93107 "uid": "old"
94108 },
95109 "maxDataPoints": 10,
96110 "refId": "Z",
97- "timeRange ": {
111+ "_timeRange ": {
98112 "from": "100",
99113 "to": "200"
100114 }
101115 }` , string (out ))
116+
117+ // The third query has a time-range with an underscore prefix
118+ require .NotNil (t , req .Queries [2 ].TimeRange )
119+ require .Equal (t , "10" , req .Queries [2 ].TimeRange .From )
120+ require .Equal (t , "20" , req .Queries [2 ].TimeRange .To )
121+ out , err = json .MarshalIndent (req .Queries [2 ], "" , " " )
122+ require .NoError (t , err )
123+ require .JSONEq (t , `{
124+ "datasource": {
125+ "type": "prometheus",
126+ "uid": "u-i-d"
127+ },
128+ "expr": "42",
129+ "refId": "Q",
130+ "_timeRange": {
131+ "from": "10",
132+ "to": "20"
133+ }
134+ }` , string (out ))
102135 })
103136
104137 t .Run ("verify deep copy" , func (t * testing.T ) {
0 commit comments