Skip to content

Commit

Permalink
with spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed Feb 14, 2024
1 parent b88a6a6 commit 46076df
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/models/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package models

import (
"reflect"
"testing"

"github.com/grafana/grafana-plugin-sdk-go/experimental/query"
"github.com/grafana/grafana-plugin-sdk-go/experimental/query/schema"
"github.com/stretchr/testify/require"
)

func TestQueryTypeDefinitions(t *testing.T) {
builder, err := schema.NewBuilder(
schema.BuilderOptions{
BasePackage: "github.com/grafana/google-sheets-datasource/pkg/models",
CodePath: "./",
},
schema.QueryTypeInfo{
Name: "default",
GoType: reflect.TypeOf(&QueryModel{}),
Examples: []query.QueryExample{
{
Name: "public query",
Query: QueryModel{
Spreadsheet: "YourSheetID",
Range: "A1:D6",
},
},
},
},
)

require.NoError(t, err)

// Update the query schemas resource
builder.UpdateSchemaDefinition(t, "../../src/static/schema/dataquery.json")
}
53 changes: 53 additions & 0 deletions src/static/schema/dataquery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"kind": "QueryTypeDefinitionList",
"apiVersion": "query.grafana.app/v0alpha1",
"metadata": {
"resourceVersion": "1707880401234"
},
"items": [
{
"metadata": {
"name": "default",
"resourceVersion": "1707880401234",
"creationTimestamp": "2024-02-14T03:13:21Z"
},
"spec": {
"schema": {
"additionalProperties": false,
"description": "QueryModel represents a spreadsheet query.",
"properties": {
"cacheDurationSeconds": {
"description": "Cache duration in seconds",
"type": "integer"
},
"range": {
"description": "A1 notation",
"type": "string"
},
"spreadsheet": {
"description": "The google sheets spreadsheet ID",
"type": "string"
},
"useTimeFilter": {
"description": "Use the query time range to filer values from the table",
"type": "boolean"
}
},
"required": [
"spreadsheet"
],
"type": "object"
},
"examples": [
{
"name": "public query",
"query": {
"range": "A1:D6",
"spreadsheet": "YourSheetID"
}
}
]
}
}
]
}

0 comments on commit 46076df

Please sign in to comment.