|
| 1 | +package spec |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/cloudquery/codegen/jsonschema" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | +) |
| 9 | + |
| 10 | +func TestCredentialsConfigJSONSchema(t *testing.T) { |
| 11 | + schema, err := jsonschema.Generate(CredentialsConfig{}) |
| 12 | + require.NoError(t, err) |
| 13 | + |
| 14 | + jsonschema.TestJSONSchema(t, string(schema), []jsonschema.TestCase{ |
| 15 | + { |
| 16 | + Name: "empty", |
| 17 | + Err: true, // missing target_principal |
| 18 | + Spec: `{}`, |
| 19 | + }, |
| 20 | + { |
| 21 | + Name: "empty target_principal", |
| 22 | + Err: true, |
| 23 | + Spec: `{"target_principal":""}`, |
| 24 | + }, |
| 25 | + { |
| 26 | + Name: "null target_principal", |
| 27 | + Err: true, |
| 28 | + Spec: `{"target_principal":null}`, |
| 29 | + }, |
| 30 | + { |
| 31 | + Name: "bad target_principal", |
| 32 | + Err: true, |
| 33 | + Spec: `{"target_principal":123}`, |
| 34 | + }, |
| 35 | + { |
| 36 | + Name: "bad target_principal format", |
| 37 | + Err: true, |
| 38 | + Spec: `{"target_principal":"some"}`, |
| 39 | + }, |
| 40 | + { |
| 41 | + Name: "proper target_principal", |
| 42 | + Spec: `{"target_principal":"a@some"}`, |
| 43 | + }, |
| 44 | + { |
| 45 | + Name: "extra field", |
| 46 | + Err: true, |
| 47 | + Spec: `{"target_principal":"a@some","extra":true}`, |
| 48 | + }, |
| 49 | + { |
| 50 | + Name: "empty scopes", |
| 51 | + Spec: `{"target_principal":"a@some", "scopes":[]}`, |
| 52 | + }, |
| 53 | + { |
| 54 | + Name: "null scopes", |
| 55 | + Spec: `{"target_principal":"a@some", "scopes":null}`, |
| 56 | + }, |
| 57 | + { |
| 58 | + Name: "bad scopes", |
| 59 | + Err: true, |
| 60 | + Spec: `{"target_principal":"a@some", "scopes":123}`, |
| 61 | + }, |
| 62 | + { |
| 63 | + Name: "empty scopes entry", |
| 64 | + Err: true, |
| 65 | + Spec: `{"target_principal":"a@some", "scopes":[""]}`, |
| 66 | + }, |
| 67 | + { |
| 68 | + Name: "null scopes entry", |
| 69 | + Err: true, |
| 70 | + Spec: `{"target_principal":"a@some", "scopes":[null]}`, |
| 71 | + }, |
| 72 | + { |
| 73 | + Name: "bad scopes entry", |
| 74 | + Err: true, |
| 75 | + Spec: `{"target_principal":"a@some", "scopes":[123]}`, |
| 76 | + }, |
| 77 | + { |
| 78 | + Name: "bad scopes entry format", |
| 79 | + Err: true, |
| 80 | + Spec: `{"target_principal":"a@some", "scopes":["https://www.g00gleapis.com/auth/cloud-platform"]}`, |
| 81 | + }, |
| 82 | + { |
| 83 | + Name: "proper scopes entry", |
| 84 | + Spec: `{"target_principal":"a@some", "scopes":["https://www.googleapis.com/auth/cloud-platform.read-only"]}`, |
| 85 | + }, |
| 86 | + |
| 87 | + { |
| 88 | + Name: "empty delegates", |
| 89 | + Spec: `{"target_principal":"a@some", "delegates":[]}`, |
| 90 | + }, |
| 91 | + { |
| 92 | + Name: "null delegates", |
| 93 | + Spec: `{"target_principal":"a@some", "delegates":null}`, |
| 94 | + }, |
| 95 | + { |
| 96 | + Name: "bad delegates", |
| 97 | + Err: true, |
| 98 | + Spec: `{"target_principal":"a@some", "delegates":123}`, |
| 99 | + }, |
| 100 | + { |
| 101 | + Name: "empty delegates entry", |
| 102 | + Err: true, |
| 103 | + Spec: `{"target_principal":"a@some", "delegates":[""]}`, |
| 104 | + }, |
| 105 | + { |
| 106 | + Name: "null delegates entry", |
| 107 | + Err: true, |
| 108 | + Spec: `{"target_principal":"a@some", "delegates":[null]}`, |
| 109 | + }, |
| 110 | + { |
| 111 | + Name: "bad delegates entry", |
| 112 | + Err: true, |
| 113 | + Spec: `{"target_principal":"a@some", "delegates":[123]}`, |
| 114 | + }, |
| 115 | + { |
| 116 | + Name: "bad delegates entry format", |
| 117 | + Err: true, |
| 118 | + Spec: `{"target_principal":"a@some", "delegates":["abc"]}`, |
| 119 | + }, |
| 120 | + { |
| 121 | + Name: "proper delegates entry", |
| 122 | + Spec: `{"target_principal":"a@some", "delegates":["a@some"]}`, |
| 123 | + }, |
| 124 | + { |
| 125 | + Name: "empty subject", |
| 126 | + Err: true, |
| 127 | + Spec: `{"target_principal":"a@some", "subject":""}`, |
| 128 | + }, |
| 129 | + { |
| 130 | + Name: "null subject", |
| 131 | + Err: true, |
| 132 | + Spec: `{"target_principal":"a@some", "subject":null}`, |
| 133 | + }, |
| 134 | + { |
| 135 | + Name: "bad subject", |
| 136 | + Err: true, |
| 137 | + Spec: `{"target_principal":"a@some", "subject":123}`, |
| 138 | + }, |
| 139 | + { |
| 140 | + Name: "proper subject", |
| 141 | + Spec: `{"target_principal":"a@some", "subject":"some"}`, |
| 142 | + }, |
| 143 | + }) |
| 144 | +} |
0 commit comments