go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers-sdk/v1/lr/schema_test.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package lr 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 "go.mondoo.com/cnquery/providers-sdk/v1/resources" 12 "go.mondoo.com/cnquery/types" 13 ) 14 15 const provider = "🐱" 16 17 func schemaFor(t *testing.T, s string) *resources.Schema { 18 ast := parse(t, s) 19 ast.Options = map[string]string{"provider": provider} 20 res, err := Schema(ast) 21 require.NoError(t, err) 22 return res 23 } 24 25 func TestSchema(t *testing.T) { 26 t.Run("empty", func(t *testing.T) { 27 res := schemaFor(t, "") 28 assert.Empty(t, res.Resources) 29 }) 30 31 t.Run("chain resource creation", func(t *testing.T) { 32 res := schemaFor(t, ` 33 platform.has.name {} 34 `) 35 require.NotEmpty(t, res.Resources) 36 require.Equal(t, &resources.ResourceInfo{ 37 Id: "platform", 38 IsExtension: true, 39 Fields: map[string]*resources.Field{ 40 "has": { 41 Name: "has", 42 Type: string(types.Resource("platform.has")), 43 Provider: provider, 44 IsImplicitResource: true, 45 }, 46 }, 47 }, res.Resources["platform"]) 48 }) 49 }