Skip to content

Commit

Permalink
with validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed Feb 25, 2024
1 parent 739bf55 commit 30a7dde
Show file tree
Hide file tree
Showing 9 changed files with 5,144 additions and 2,684 deletions.
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.3
require (
github.com/google/go-github/v53 v53.2.0
github.com/gorilla/mux v1.8.0
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240221213513-1202776612ce
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240225155948-2c8c4ada2764
github.com/influxdata/tdigest v0.0.1
github.com/pkg/errors v0.9.1
github.com/shurcooL/githubv4 v0.0.0-20230305132112-efb623903184
Expand All @@ -20,6 +20,7 @@ require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/apache/arrow/go/v15 v15.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand All @@ -32,9 +33,11 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 // indirect
Expand Down Expand Up @@ -80,6 +83,8 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
)

require (
Expand Down
24 changes: 16 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/apache/arrow/go/v15 v15.0.0 h1:1zZACWf85oEZY5/kd9dsQS7i+2G5zVQcbKTHgs
github.com/apache/arrow/go/v15 v15.0.0/go.mod h1:DGXsR3ajT524njufqf95822i+KTh+yea1jass9YXgjA=
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down Expand Up @@ -76,6 +78,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
Expand All @@ -99,6 +103,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/flatbuffers v23.5.26+incompatible h1:M9dgRyhJemaM4Sw8+66GHBu8ioaQmyPLg1b8VwK5WJg=
github.com/google/flatbuffers v23.5.26+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand All @@ -109,20 +115,16 @@ github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSX
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240217022158-238f7c9d8816 h1:m1JayeML+QidooyEt1CPAfRG37Znf8fUyZzkLcy182A=
github.com/grafana/grafana-plugin-sdk-go v0.211.1-0.20240217022158-238f7c9d8816/go.mod h1:udcOq6XFvGNKu427UuCSGOO1bMT+JPSa1Cz4YE2xB0o=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240220160848-1fe487a68394 h1:YYpO/Bt3ZYC4MIoBxDTYxSR14DEWiaS0GbxlwvAba6E=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240220160848-1fe487a68394/go.mod h1:udcOq6XFvGNKu427UuCSGOO1bMT+JPSa1Cz4YE2xB0o=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240221212145-f5a35b3a396b h1:boHS6WmCQtP3cc5btibHu0UYGK8OFvoy+/mOCiRlVhA=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240221212145-f5a35b3a396b/go.mod h1:udcOq6XFvGNKu427UuCSGOO1bMT+JPSa1Cz4YE2xB0o=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240221213513-1202776612ce h1:3Wfn8dDSnuyN+/54Gmjm5U5MvHUuAIcnxBoOAqtw8ug=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240221213513-1202776612ce/go.mod h1:udcOq6XFvGNKu427UuCSGOO1bMT+JPSa1Cz4YE2xB0o=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240225155948-2c8c4ada2764 h1:/BTLulhqMEDZ22R5aHlPPcRthmzB3Wtbd65kNbmduyg=
github.com/grafana/grafana-plugin-sdk-go v0.212.1-0.20240225155948-2c8c4ada2764/go.mod h1:qhc1+zxfvv+avgJGvFaNw3h6WHtO2d6sHOQhzfezL+A=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
Expand Down Expand Up @@ -437,5 +439,11 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5 h1:QSpdNrZ9uRlV0VkqLvVO0Rqg8ioKi3oSw7O5P7pJV8M=
k8s.io/kube-openapi v0.0.0-20240220201932-37d671a357a5/go.mod h1:Pa1PvrP7ACSkuX6I7KYomY6cmMA0Tx86waBhDUgoKPw=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
pgregory.net/rapid v1.0.0 h1:iQaM2w5PZ6xvt6x7hbd7tiDS+nk7YPp5uCaEba+T/F4=
pgregory.net/rapid v1.0.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
71 changes: 46 additions & 25 deletions pkg/models/schema_test.go → pkg/models/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/grafana/grafana-plugin-sdk-go/experimental/spec"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/require"
)

Expand All @@ -17,8 +18,8 @@ func TestSchemaDefinitions(t *testing.T) {
)

common := Query{
Repository: "repo",
Owner: "owner",
Repository: "github-datasource",
Owner: "grafana",
}

require.NoError(t, err)
Expand All @@ -28,8 +29,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "Simple",
QueryPayload: PullRequestsQuery{
Query: common,
SaveModel: PullRequestsQuery{
Query: common,
Options: ListPullRequestsOptions{},
},
},
},
Expand All @@ -39,8 +41,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "CommitsQuery",
QueryPayload: CommitsQuery{
Query: common,
SaveModel: CommitsQuery{
Query: common,
Options: ListCommitsOptions{},
},
},
},
Expand All @@ -50,8 +53,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "TagsQuery",
QueryPayload: TagsQuery{
Query: common,
SaveModel: TagsQuery{
Query: common,
Options: ListTagsOptions{},
},
},
},
Expand All @@ -61,8 +65,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "LabelsQuery",
QueryPayload: LabelsQuery{
Query: common,
SaveModel: LabelsQuery{
Query: common,
Options: ListLabelsOptions{},
},
},
},
Expand All @@ -72,8 +77,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "ReleasesQuery",
QueryPayload: ReleasesQuery{
Query: common,
SaveModel: ReleasesQuery{
Query: common,
Options: ListReleasesOptions{},
},
},
},
Expand All @@ -83,8 +89,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "ContributorsQuery",
QueryPayload: ContributorsQuery{
Query: common,
SaveModel: ContributorsQuery{
Query: common,
Options: ListContributorsOptions{Owner: "yesoreyeram"},
},
},
},
Expand All @@ -94,8 +101,10 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "RepositoriesQuery",
QueryPayload: RepositoriesQuery{
Query: common,
SaveModel: RepositoriesQuery{
Query: Query{
Owner: "yesoreyeram",
},
},
},
},
Expand All @@ -105,8 +114,15 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "IssuesQuery",
QueryPayload: IssuesQuery{
SaveModel: IssuesQuery{
Query: common,
Options: ListIssuesOptions{
Filters: &githubv4.IssueFilters{
States: &[]githubv4.IssueState{
githubv4.IssueStateOpen,
},
},
},
},
},
},
Expand All @@ -116,8 +132,11 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "PackagesQuery",
QueryPayload: PackagesQuery{
SaveModel: PackagesQuery{
Query: common,
Options: ListPackagesOptions{
PackageType: githubv4.PackageTypeDocker,
},
},
},
},
Expand All @@ -127,7 +146,7 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "MilestonesQuery",
QueryPayload: MilestonesQuery{
SaveModel: MilestonesQuery{
Query: common,
},
},
Expand All @@ -138,7 +157,7 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "VulnerabilityQuery",
QueryPayload: VulnerabilityQuery{
SaveModel: VulnerabilityQuery{
Query: common,
},
},
Expand All @@ -149,7 +168,7 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "StargazersQuery",
QueryPayload: StargazersQuery{
SaveModel: StargazersQuery{
Query: common,
},
},
Expand All @@ -160,8 +179,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "WorkflowsQuery",
QueryPayload: WorkflowsQuery{
Query: common,
SaveModel: WorkflowsQuery{
Query: common,
Options: ListWorkflowsOptions{},
},
},
},
Expand All @@ -171,8 +191,9 @@ func TestSchemaDefinitions(t *testing.T) {
Examples: []spec.QueryExample{
{
Name: "WorkflowUsageQuery",
QueryPayload: WorkflowUsageQuery{
Query: common,
SaveModel: WorkflowUsageQuery{
Query: common,
Options: WorkflowUsageOptions{},
},
},
},
Expand Down
Loading

0 comments on commit 30a7dde

Please sign in to comment.