|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/cloudquery/codegen/jsonschema" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func TestJSONSchema(t *testing.T) { |
| 11 | + jsonschema.TestJSONSchema(t, JSONSchema, []jsonschema.TestCase{ |
| 12 | + { |
| 13 | + Name: "empty spec", |
| 14 | + Spec: `{}`, |
| 15 | + Err: true, |
| 16 | + }, |
| 17 | + { |
| 18 | + Name: "spec with token", |
| 19 | + Spec: `{"token": "tok"}`, |
| 20 | + Err: true, |
| 21 | + }, |
| 22 | + { |
| 23 | + Name: "spec with domain", |
| 24 | + Spec: `{"domain": "https://domain.okta.com"}`, |
| 25 | + Err: true, |
| 26 | + }, |
| 27 | + { |
| 28 | + Name: "spec with token and domain", |
| 29 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com"}`, |
| 30 | + }, |
| 31 | + { |
| 32 | + Name: "spec with token and invalid domain", |
| 33 | + Spec: `{"token": "tok", "domain": "https://<CHANGE_THIS_TO_YOUR_OKTA_DOMAIN>.okta.com"}`, |
| 34 | + Err: true, |
| 35 | + }, |
| 36 | + { |
| 37 | + Name: "spec with token and domain and empty rate limit", |
| 38 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": {}}`, |
| 39 | + }, |
| 40 | + { |
| 41 | + Name: "spec with token and domain and null rate limit", |
| 42 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": null}`, |
| 43 | + }, |
| 44 | + { |
| 45 | + Name: "spec with token and domain and valid rate limit", |
| 46 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": {"max_backoff": "60s"}}`, |
| 47 | + }, |
| 48 | + { |
| 49 | + Name: "spec with bool concurrency", |
| 50 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":false}`, |
| 51 | + Err: true, |
| 52 | + }, |
| 53 | + { |
| 54 | + Name: "spec with null concurrency", |
| 55 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":null}`, |
| 56 | + Err: true, |
| 57 | + }, |
| 58 | + { |
| 59 | + Name: "spec with string concurrency", |
| 60 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":"str"}`, |
| 61 | + Err: true, |
| 62 | + }, |
| 63 | + { |
| 64 | + Name: "spec with proper concurrency", |
| 65 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency": 7}`, |
| 66 | + }, |
| 67 | + { |
| 68 | + Name: "spec with array concurrency", |
| 69 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":["abc"]}`, |
| 70 | + Err: true, |
| 71 | + }, |
| 72 | + { |
| 73 | + Name: "spec with unknown field", |
| 74 | + Spec: `{"token": "tok", "domain": "https://domain.okta.com", "unknown": "test"}`, |
| 75 | + Err: true, |
| 76 | + }, |
| 77 | + }) |
| 78 | +} |
| 79 | + |
| 80 | +func TestRateLimitJSONSchema(t *testing.T) { |
| 81 | + data, err := jsonschema.Generate(RateLimit{}) |
| 82 | + require.NoError(t, err) |
| 83 | + |
| 84 | + jsonschema.TestJSONSchema(t, string(data), []jsonschema.TestCase{ |
| 85 | + { |
| 86 | + Name: "empty", |
| 87 | + Spec: `{}`, |
| 88 | + }, |
| 89 | + { |
| 90 | + Name: "valid max_backoff", |
| 91 | + Spec: `{"max_backoff": "60s"}`, |
| 92 | + }, |
| 93 | + { |
| 94 | + Name: "invalid max_backoff", |
| 95 | + Spec: `{"max_backoff": true}`, |
| 96 | + Err: true, |
| 97 | + }, |
| 98 | + { |
| 99 | + Name: "zero max_backoff", |
| 100 | + Spec: `{"max_backoff": 0}`, |
| 101 | + Err: true, |
| 102 | + }, |
| 103 | + { |
| 104 | + Name: "unknown field", |
| 105 | + Spec: `{"unknown": "test"}`, |
| 106 | + Err: true, |
| 107 | + }, |
| 108 | + }) |
| 109 | +} |
0 commit comments