Skip to content

Commit

Permalink
🧹 ensure providers to run lint are installed for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Jan 21, 2024
1 parent 18de21e commit 5769a88
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,47 @@ import (
"github.com/stretchr/testify/require"
"go.mondoo.com/cnquery/v10/explorer"
"go.mondoo.com/cnquery/v10/internal/bundle"
"go.mondoo.com/cnquery/v10/providers"
"os"
"testing"
)

func ensureProviders(ids []string) error {
for _, id := range ids {
_, err := providers.EnsureProvider(providers.ProviderLookup{ID: id}, true, nil)
if err != nil {
return err
}
}
return nil
}

func TestMain(m *testing.M) {
dir := ".lint-providers"
providers.CustomProviderPath = dir
providers.DefaultPath = dir

err := ensureProviders([]string{
"go.mondoo.com/cnquery/providers/os",
"go.mondoo.com/cnquery/providers/k8s",
})
if err != nil {
panic(err)
}

exitVal := m.Run()

// cleanup custom provider path to ensure no leftovers and other tests are not affected
err = os.RemoveAll(dir)
if err != nil {
panic(err)
}

os.Exit(exitVal)
}

func TestExampleLint(t *testing.T) {

queryPackBundle, err := explorer.BundleFromPaths(".")
require.NoError(t, err)

Expand Down

0 comments on commit 5769a88

Please sign in to comment.