Skip to content

Commit

Permalink
Chore: Fix DeepCopyInto for DataQuery (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtreece authored Sep 11, 2024
1 parent 84021fd commit 71cd88b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion experimental/apis/data/v0alpha1/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (g *DataQuery) DeepCopyInto(out *DataQuery) {
out.additional = map[string]any{}
if len(g.additional) > 0 {
jj, err := json.Marshal(g.additional)
if err != nil {
if err == nil {
_ = json.Unmarshal(jj, &out.additional)
}
}
Expand Down
8 changes: 7 additions & 1 deletion experimental/apis/data/v0alpha1/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
"spreadsheet": "spreadsheetID",
"datasourceId": 4,
"intervalMs": 30000,
"maxDataPoints": 794
"maxDataPoints": 794,
"expr": "{filename=\"/var/log/docker/2e21a640173f1f3359e2a178905dad6b1b56e2da6e3d53dbdba0a1123cdcb4fe/json.log\"} | logfmt"
},
{
"refId": "Z",
Expand Down Expand Up @@ -75,6 +76,11 @@ func TestParseQueriesIntoQueryDataRequest(t *testing.T) {
}`, string(out))
})

t.Run("verify deep copy", func(t *testing.T) {
cpy := req.DeepCopy()
require.Equal(t, req, cpy)
})

t.Run("same results from either parser", func(t *testing.T) {
typed := &QueryDataRequest{}
err = json.Unmarshal(request, typed)
Expand Down

0 comments on commit 71cd88b

Please sign in to comment.