Skip to content

Commit

Permalink
cleanup test configuration settings
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Oct 12, 2023
1 parent 442cdcb commit d50b30a
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 125 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONDOO_API_TOKEN=xxxx
MONDOO_GQL_ENDPOINT=https://api.edge.mondoo.com/query
5 changes: 0 additions & 5 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ jobs:
- name: Wait a bit for the runner to become more stable
run: for i in 1 2 3 4 5; do kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=180s && break || sleep 10; done

# There are connection timeouts set to 30s in the k8s components. This means that they might seem like
# they are working but in fact they are just waiting on a connection.
- name: Wait for 40s
run: sleep 40

- name: Run integration tests
env:
MONDOO_SERVICE_ACCOUNT_EDGE: ${{ secrets.MONDOO_SERVICE_ACCOUNT_EDGE}}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ tests/integration/_output
/cnquery
/cnspec

package.json
package.json
.env
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"gopls": {
"formatting.gofumpt": true,
},
"go.testEnvFile": "${workspaceFolder}/.env",
}
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
ifneq (,$(wildcard ./.env))
include .env
export
endif

# VERSION defines the project version for the bundle.
# Update this value when you upgrade the version of your project.
# To re-generate a bundle for another specific version without changing the standard setup, you can:
Expand Down
26 changes: 19 additions & 7 deletions tests/framework/nexus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@
package nexus

import (
"go.mondoo.com/cnquery/v9/providers-sdk/v1/upstream"
"fmt"
"os"

mondoogql "go.mondoo.com/mondoo-go"
"go.mondoo.com/mondoo-go/option"
)

type Client struct {
spaceMrn string
const (
MONDOO_API_TOKEN_VAR = "MONDOO_API_TOKEN"
MONDOO_GQL_ENDPOINT_VAR = "MONDOO_GQL_ENDPOINT"
)

type Client struct {
Client *mondoogql.Client
}

func NewClient(serviceAccount *upstream.ServiceAccountCredentials) (*Client, error) {
func NewClient() (*Client, error) {
gqlEndpoint := os.Getenv(MONDOO_GQL_ENDPOINT_VAR)
if gqlEndpoint == "" {
return nil, fmt.Errorf("missing environment variable %s", MONDOO_GQL_ENDPOINT_VAR)
}

apiToken := os.Getenv(MONDOO_API_TOKEN_VAR)
if apiToken == "" {
return nil, fmt.Errorf("missing environment variable %s", MONDOO_API_TOKEN_VAR)
}
// Initialize the client
client, err := mondoogql.NewClient(option.WithEndpoint("https://api.edge.mondoo.com/query"), option.WithAPIToken(""))
client, err := mondoogql.NewClient(option.WithEndpoint(gqlEndpoint), option.WithAPIToken(apiToken))
if err != nil {
return nil, err
}

return &Client{
spaceMrn: serviceAccount.ParentMrn,
Client: client,
Client: client,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion tests/framework/nexus/k8s/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type CiCdJob struct {
Grade string
}

func (p *CiCdProject) ListAssets(ctx context.Context, assetType string) ([]CiCdJob, error) {
func (p *CiCdProject) ListAssets(ctx context.Context) ([]CiCdJob, error) {
var q struct {
CicdProjectJobs struct {
Jobs struct {
Expand Down
35 changes: 0 additions & 35 deletions tests/framework/utils/service_account.go

This file was deleted.

9 changes: 3 additions & 6 deletions tests/integration/audit_config_base_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ func (s *AuditConfigBaseSuite) SetupSuite() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
s.ctx = context.Background()

sa, err := utils.GetServiceAccount()
s.Require().NoError(err, "Service account not set")
nexusClient, err := nexus.NewClient(sa)

nexusClient, err := nexus.NewClient()
s.Require().NoError(err, "Failed to create Nexus client")
s.spaceClient = nexusClient.GetSpace()

Expand Down Expand Up @@ -808,7 +805,7 @@ func (s *AuditConfigBaseSuite) checkDeployments(auditConfig *mondoov2.MondooAudi
cicdProject, err := s.integration.GetCiCdProject(s.ctx)
s.Require().NoError(err, "Failed to get CICD project")

assets, err := cicdProject.ListAssets(s.ctx, "")
assets, err := cicdProject.ListAssets(s.ctx)
s.Require().NoError(err, "Failed to list CICD assets")

assetNames := utils.CiCdJobNames(assets)
Expand All @@ -824,7 +821,7 @@ func (s *AuditConfigBaseSuite) checkDeployments(auditConfig *mondoov2.MondooAudi
s.NoErrorf(err, "Failed creating a Deployment in permissive mode.")
}

assets, err = cicdProject.ListAssets(s.ctx, "")
assets, err = cicdProject.ListAssets(s.ctx)
s.Require().NoError(err, "Failed to list CICD assets")

assetNames = utils.CiCdJobNames(assets)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/audit_config_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (s *AuditConfigCustomNamespaceSuite) TestReconcile_KubernetesResources() {

func (s *AuditConfigCustomNamespaceSuite) TestReconcile_Containers() {
auditConfig := utils.DefaultAuditConfigMinimal(s.ns.Name, false, true, false, false)
auditConfig.Spec.Scanner.ServiceAccountName = s.sa.Name

// Ignore the operator namespace and the scanner namespace because we cannot scan a local image
auditConfig.Spec.Filtering.Namespaces.Exclude = []string{s.ns.Name, s.testCluster.Settings.Namespace, "kube-system"}
Expand Down
70 changes: 0 additions & 70 deletions tests/integration/gql_test.go

This file was deleted.

0 comments on commit d50b30a

Please sign in to comment.