|
| 1 | +package schema |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "encoding/json" |
| 6 | + "npm/internal/entity/certificate" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestSchemas(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + schema string |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "CreateCertificate", |
| 19 | + schema: CreateCertificate(), |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "UpdateCertificate TypeHTTP", |
| 23 | + schema: UpdateCertificate(certificate.TypeHTTP), |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "UpdateCertificate TypeDNS", |
| 27 | + schema: UpdateCertificate(certificate.TypeDNS), |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "UpdateCertificate TypeCustom", |
| 31 | + schema: UpdateCertificate(certificate.TypeCustom), |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "UpdateCertificate TypeMkcert", |
| 35 | + schema: UpdateCertificate(certificate.TypeMkcert), |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "UpdateCertificate default", |
| 39 | + schema: UpdateCertificate(""), |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "CreateAccessList", |
| 43 | + schema: CreateAccessList(), |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "CreateCertificateAuthority", |
| 47 | + schema: CreateCertificateAuthority(), |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "CreateDNSProvider", |
| 51 | + schema: CreateDNSProvider(), |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "CreateHost", |
| 55 | + schema: CreateHost(), |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "CreateNginxTemplate", |
| 59 | + schema: CreateNginxTemplate(), |
| 60 | + }, |
| 61 | + { |
| 62 | + name: "CreateSetting", |
| 63 | + schema: CreateSetting(), |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "CreateStream", |
| 67 | + schema: CreateStream(), |
| 68 | + }, |
| 69 | + { |
| 70 | + name: "CreateUpstream", |
| 71 | + schema: CreateUpstream(), |
| 72 | + }, |
| 73 | + { |
| 74 | + name: "CreateUser", |
| 75 | + schema: CreateUser(), |
| 76 | + }, |
| 77 | + { |
| 78 | + name: "GetToken", |
| 79 | + schema: GetToken(), |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "SetAuth", |
| 83 | + schema: SetAuth(), |
| 84 | + }, |
| 85 | + { |
| 86 | + name: "UpdateAccessList", |
| 87 | + schema: UpdateAccessList(), |
| 88 | + }, |
| 89 | + { |
| 90 | + name: "UpdateCertificateAuthority", |
| 91 | + schema: UpdateCertificateAuthority(), |
| 92 | + }, |
| 93 | + { |
| 94 | + name: "UpdateDNSProvider", |
| 95 | + schema: UpdateDNSProvider(), |
| 96 | + }, |
| 97 | + { |
| 98 | + name: "UpdateHost", |
| 99 | + schema: UpdateHost(), |
| 100 | + }, |
| 101 | + { |
| 102 | + name: "UpdateNginxTemplate", |
| 103 | + schema: UpdateNginxTemplate(), |
| 104 | + }, |
| 105 | + { |
| 106 | + name: "UpdateSetting", |
| 107 | + schema: UpdateSetting(), |
| 108 | + }, |
| 109 | + { |
| 110 | + name: "UpdateStream", |
| 111 | + schema: UpdateStream(), |
| 112 | + }, |
| 113 | + { |
| 114 | + name: "UpdateUpstream", |
| 115 | + schema: UpdateUpstream(), |
| 116 | + }, |
| 117 | + { |
| 118 | + name: "UpdateUser", |
| 119 | + schema: UpdateUser(), |
| 120 | + }, |
| 121 | + } |
| 122 | + |
| 123 | + for _, tt := range tests { |
| 124 | + t.Run(tt.name, func(t *testing.T) { |
| 125 | + byt := []byte(tt.schema) |
| 126 | + var prettyJSON bytes.Buffer |
| 127 | + err := json.Indent(&prettyJSON, byt, "", " ") |
| 128 | + assert.NoError(t, err) |
| 129 | + assert.Greater(t, len(prettyJSON.String()), 0) |
| 130 | + }) |
| 131 | + } |
| 132 | +} |
0 commit comments