diff --git a/mqlc/mqlc_test.go b/mqlc/mqlc_test.go index 76bdc8e3a8..b3b92a8ac3 100644 --- a/mqlc/mqlc_test.go +++ b/mqlc/mqlc_test.go @@ -15,15 +15,16 @@ import ( "go.mondoo.com/cnquery/llx" "go.mondoo.com/cnquery/logger" "go.mondoo.com/cnquery/mqlc" - "go.mondoo.com/cnquery/providers" "go.mondoo.com/cnquery/types" + + "go.mondoo.com/cnquery/providers-sdk/v1/testutils" ) var ( features = cnquery.Features{} - os_schema = providers.MustLoadSchemaFromFile("os", "../providers/os/resources/os.resources.json") - core_schema = providers.MustLoadSchemaFromFile("core", "../providers/core/resources/core.resources.json") - azure_schema = providers.MustLoadSchemaFromFile("azure", "../providers/azure/resources/azure.resources.json") + os_schema = testutils.MustLoadSchema(testutils.SchemaProvider{Provider: "os"}) + core_schema = testutils.MustLoadSchema(testutils.SchemaProvider{Provider: "core"}) + azure_schema = testutils.MustLoadSchema(testutils.SchemaProvider{Provider: "azure"}) conf = mqlc.NewConfig( core_schema.Add(os_schema).Add(azure_schema), features, diff --git a/providers-sdk/v1/testutils/testutils.go b/providers-sdk/v1/testutils/testutils.go index 4dbad40a1d..694a635762 100644 --- a/providers-sdk/v1/testutils/testutils.go +++ b/providers-sdk/v1/testutils/testutils.go @@ -81,6 +81,11 @@ type tester struct { Runtime llx.Runtime } +type SchemaProvider struct { + Provider string + Path string +} + func InitTester(runtime llx.Runtime) *tester { return &tester{ Runtime: runtime, @@ -150,12 +155,21 @@ func (ctx *tester) TestMqlc(t *testing.T, bundle *llx.CodeBundle, props map[stri return results } -func mustLoadSchema(provider string) *resources.Schema { +func MustLoadSchema(provider SchemaProvider) *resources.Schema { + if provider.Path == "" && provider.Provider == "" { + panic("cannot load schema without provider name or path") + } var path string - if provider == "mockprovider" { - path = filepath.Join(TestutilsDir, "mockprovider/resources/mockprovider.lr") - } else { - path = filepath.Join(TestutilsDir, "../../../providers/"+provider+"/resources/"+provider+".lr") + if provider.Provider != "" { + switch provider.Provider { + // special handling for the mockprovider + case "mockprovider": + path = filepath.Join(TestutilsDir, "mockprovider/resources/mockprovider.lr") + default: + path = filepath.Join(TestutilsDir, "../../../providers/"+provider.Provider+"/resources/"+provider.Provider+".lr") + } + } else if provider.Path != "" { + path = provider.Path } res, err := lr.Resolve(path, func(path string) ([]byte, error) { return os.ReadFile(path) }) @@ -172,10 +186,10 @@ func mustLoadSchema(provider string) *resources.Schema { } func Local() llx.Runtime { - osSchema := mustLoadSchema("os") - coreSchema := mustLoadSchema("core") - networkSchema := mustLoadSchema("network") - mockSchema := mustLoadSchema("mockprovider") + osSchema := MustLoadSchema(SchemaProvider{Provider: "os"}) + coreSchema := MustLoadSchema(SchemaProvider{Provider: "core"}) + networkSchema := MustLoadSchema(SchemaProvider{Provider: "network"}) + mockSchema := MustLoadSchema(SchemaProvider{Provider: "mockprovider"}) runtime := providers.Coordinator.NewRuntime()