-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧹 ensure example pass our own lint requirements
- Loading branch information
1 parent
7676446
commit 7dd4497
Showing
5 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
policies: | ||
- uid: ssh-policy | ||
name: SSH Policy | ||
version: 1.0.0 | ||
groups: | ||
- filters: return true | ||
checks: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package examples | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.mondoo.com/cnquery/v10/providers" | ||
"go.mondoo.com/cnspec/v10/internal/bundle" | ||
"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", | ||
}) | ||
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) { | ||
files := []string{ | ||
"./complex.mql.yaml", | ||
"./example.mql.yaml", | ||
"./props.mql.yaml", | ||
} | ||
|
||
runtime := providers.DefaultRuntime() | ||
result, err := bundle.Lint(runtime.Schema(), files...) | ||
require.NoError(t, err) | ||
assert.False(t, result.HasError()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters