Skip to content

Commit

Permalink
🧹 remove deprecated providers/mock (#1851)
Browse files Browse the repository at this point in the history
We already have the mock provider, which is not a standalone provider anymore but part of the providers engine now. You can find it in `providers/mock.go`. The provider in the folder is a relic of earlier iterations now and can be removed.

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Sep 22, 2023
1 parent 66756d7 commit ed91e80
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 311 deletions.
19 changes: 1 addition & 18 deletions cli/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
package shell_test

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"go.mondoo.com/cnquery/cli/shell"
"go.mondoo.com/cnquery/providers-sdk/v1/testutils"
"go.mondoo.com/cnquery/providers/mock"
)

func localShell() *shell.Shell {
Expand All @@ -23,21 +21,6 @@ func localShell() *shell.Shell {
return res
}

func mockShell(filename string, opts ...shell.ShellOption) *shell.Shell {
path, _ := filepath.Abs(filename)
runtime, err := mock.NewFromTomlFile(path)
if err != nil {
panic(err.Error())
}

res, err := shell.New(runtime, opts...)
if err != nil {
panic(err.Error())
}

return res
}

func TestShell_RunOnce(t *testing.T) {
shell := localShell()
assert.NotPanics(t, func() {
Expand Down Expand Up @@ -65,7 +48,7 @@ func TestShell_Help(t *testing.T) {
}

func TestShell_Centos8(t *testing.T) {
shell := mockShell("../../mql/testdata/centos8.toml")
shell := localShell()
assert.NotPanics(t, func() {
shell.RunOnce("platform { title name release arch }")
}, "should not panic on partial queries")
Expand Down
15 changes: 11 additions & 4 deletions providers-sdk/v1/inventory/manager/credentials_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mondoo.com/cnquery/llx"
"go.mondoo.com/cnquery/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/providers-sdk/v1/inventory/manager"
"go.mondoo.com/cnquery/providers-sdk/v1/testutils"
"go.mondoo.com/cnquery/providers-sdk/v1/vault"
"go.mondoo.com/cnquery/providers/mock"
)

var runtime llx.Runtime

func init() {
runtime = testutils.LinuxMock()
}

func TestSecretKeySimple(t *testing.T) {
query := `{ type: 'ssh_agent' }`
runner, err := manager.NewCredentialQueryRunner(query, mock.New())
runner, err := manager.NewCredentialQueryRunner(query, runtime)
require.NoError(t, err)
cred, err := runner.Run(&inventory.Asset{})
require.NoError(t, err)
Expand All @@ -31,7 +38,7 @@ func TestSecretKeyIfReturn(t *testing.T) {
return {type: 'private_key', secret_id: 'otherkey'}
`

runner, err := manager.NewCredentialQueryRunner(query, mock.New())
runner, err := manager.NewCredentialQueryRunner(query, runtime)
require.NoError(t, err)

cred, err := runner.Run(&inventory.Asset{
Expand All @@ -53,7 +60,7 @@ func TestSecretKeyIfConditionalReturn(t *testing.T) {
return { secret_id: '' }"
`

runner, err := manager.NewCredentialQueryRunner(query, mock.New())
runner, err := manager.NewCredentialQueryRunner(query, runtime)
require.NoError(t, err)

// check with provided label
Expand Down
14 changes: 0 additions & 14 deletions providers-sdk/v1/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"go.mondoo.com/cnquery/providers-sdk/v1/lr/docs"
"go.mondoo.com/cnquery/providers-sdk/v1/resources"
"go.mondoo.com/cnquery/providers-sdk/v1/testutils/mockprovider"
"go.mondoo.com/cnquery/providers/mock"
networkconf "go.mondoo.com/cnquery/providers/network/config"
networkprovider "go.mondoo.com/cnquery/providers/network/provider"
osconf "go.mondoo.com/cnquery/providers/os/config"
Expand Down Expand Up @@ -70,15 +69,6 @@ func getEnvFeatures() cnquery.Features {
return fts
}

func TomlMock(filepath string) llx.Runtime {
trans, err := mock.NewFromTomlFile(filepath)
if err != nil {
panic(err.Error())
}

return trans
}

type tester struct {
Runtime llx.Runtime
}
Expand Down Expand Up @@ -289,10 +279,6 @@ func RecordingMock(absTestdataPath string) llx.Runtime {
return mockRuntimeAbs(absTestdataPath)
}

func CustomMock(path string) llx.Runtime {
return TomlMock(path)
}

type SimpleTest struct {
Code string
ResultIndex int
Expand Down
275 changes: 0 additions & 275 deletions providers/mock/mock.go

This file was deleted.

0 comments on commit ed91e80

Please sign in to comment.