Skip to content

Commit

Permalink
🧹 more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Dec 27, 2024
1 parent 5b18b99 commit 8e61f82
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions test/providers/github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package providers

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mondoo.com/cnquery/v11/test"
)

func TestGithubScanFlags(t *testing.T) {
once.Do(setup)

t.Run("github scan WITHOUT flags", func(t *testing.T) {
// NOTE this will fail but, it will load the flags and fail with the right message
r := test.NewCliTestRunner("./cnquery", "scan", "github", "repo", "foo")
err := r.Run()
require.NoError(t, err)
assert.Equal(t, 0, r.ExitCode())
assert.NotNil(t, r.Stdout())
assert.NotNil(t, r.Stderr())

assert.Contains(t, string(r.Stderr()),
"a valid GitHub authentication is required",
)
})
t.Run("github scan WITH flags but missing app auth key", func(t *testing.T) {
// NOTE this will fail but, it will load the flags and fail with the right message
r := test.NewCliTestRunner("./cnquery", "scan", "github", "repo", "foo",
"--app-id", "123", "--app-installation-id", "456",
)
err := r.Run()
require.NoError(t, err)
assert.Equal(t, 1, r.ExitCode())
assert.NotNil(t, r.Stdout())
assert.NotNil(t, r.Stderr())

assert.Contains(t, string(r.Stderr()),
"could not parse private key", // expected! it means we loaded the flags
)
})
t.Run("github scan WITH all required flags for app auth", func(t *testing.T) {
// NOTE this will fail but, it will load the flags and fail with the right message
r := test.NewCliTestRunner("./cnquery", "scan", "github", "repo", "foo",
"--app-id", "123", "--app-installation-id", "456", "--app-private-key", "private-key.pem",
)
err := r.Run()
require.NoError(t, err)
assert.Equal(t, 1, r.ExitCode())
assert.NotNil(t, r.Stdout())
assert.NotNil(t, r.Stderr())

assert.Contains(t, string(r.Stderr()),
"could not read private key", // expected! it means we loaded the flags
)
})
}
2 changes: 1 addition & 1 deletion test/providers/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var once sync.Once

// setup builds cnquery locally
func setup() {
// build cnspec
// build cnquery
if err := exec.Command("go", "build", "../../apps/cnquery/cnquery.go").Run(); err != nil {
log.Fatalf("building cnquery: %v", err)
}
Expand Down

0 comments on commit 8e61f82

Please sign in to comment.