github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/tracing/config_test.go (about) 1 package tracing 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 "github.com/tidwall/sjson" 12 13 "github.com/ory/jsonschema/v3" 14 ) 15 16 const rootSchema = `{ 17 "properties": { 18 "tracing": { 19 "$ref": "%s" 20 } 21 } 22 } 23 ` 24 25 func TestConfigSchema(t *testing.T) { 26 t.Run("func=AddConfigSchema", func(t *testing.T) { 27 c := jsonschema.NewCompiler() 28 require.NoError(t, AddConfigSchema(c)) 29 30 conf := Config{ 31 ServiceName: "Ory X", 32 Provider: "jaeger", 33 Providers: &ProvidersConfig{ 34 Jaeger: &JaegerConfig{ 35 LocalAgentAddress: "jaeger:6831", 36 Sampling: &JaegerSampling{ 37 Type: "const", 38 Value: 1, 39 ServerURL: "https://localhost:5778/sampling", 40 }, 41 Propagation: "jaeger", 42 MaxTagValueLength: 100, 43 }, 44 Zipkin: &ZipkinConfig{ 45 ServerURL: "https://example.com", 46 }, 47 }, 48 } 49 50 rawConfig, err := sjson.Set("{}", "tracing", &conf) 51 require.NoError(t, err) 52 53 require.NoError(t, c.AddResource("config", bytes.NewBufferString(fmt.Sprintf(rootSchema, ConfigSchemaID)))) 54 55 schema, err := c.Compile(context.Background(), "config") 56 require.NoError(t, err) 57 58 assert.NoError(t, schema.Validate(bytes.NewBufferString(rawConfig))) 59 }) 60 }