Skip to content

Commit

Permalink
Move all arango tests to common integration test suite. (#1660)
Browse files Browse the repository at this point in the history
* Move all arango tests to common integretation test suite.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

* Update some keyvalue tests for unknown dep type expected in isDep

These should be deleted in favor of internal/testing/backend, but just update a
couple for now, and remove the isDep tests.

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

* Don't run integration tests in parallel

Signed-off-by: Jeff Mendoza <jlm@jlm.name>

---------

Signed-off-by: Jeff Mendoza <jlm@jlm.name>
  • Loading branch information
jeffmendoza committed Jan 24, 2024
1 parent f393612 commit c628147
Show file tree
Hide file tree
Showing 36 changed files with 22,744 additions and 680 deletions.
8 changes: 5 additions & 3 deletions Makefile
Expand Up @@ -23,7 +23,9 @@ test: generate
# To run it locally you can run the following command: make start-integration-service
.PHONY: integration-test
integration-test: generate check-env
go test -tags=integration ./...
# "-p 1" because We don't want the tests in internal/testing/backend
# and pkg/assembler/backend running at same time
go test -p 1 -tags=integration ./...

# Runs the integration tests locally using docker-compose to start the dependencies and cleans up after itself.
.PHONY: integration-test-local
Expand All @@ -37,7 +39,7 @@ integration-test-local: generate check-env start-integration-service
counter=$$((counter+1)); \
done; \
[ $$counter -eq 15 ] && { echo "Service did not start in time"; exit 1; } || echo "Service is up!"
ENT_TEST_DATABASE_URL='postgresql://guac:guac@localhost/guac?sslmode=disable' go test -tags=integration ./...
ENT_TEST_DATABASE_URL='postgresql://guac:guac@localhost/guac?sslmode=disable' go test -p 1 -tags=integration ./...
$(CONTAINER) compose down

.PHONY: integration-merge-test
Expand Down Expand Up @@ -227,7 +229,7 @@ start-ent-db: check-docker-compose-tool-check
[ $$counter -eq 15 ] && { echo "Ent GUAC service did not start in time"; exit 1; } || echo "Ent GUAC service is up!"


# This is a helper target to run the integration tests locally.
# This is a helper target to run the integration tests locally.
.PHONY: start-integration-service
start-integration-service: check-docker-compose-tool-check
$(CONTAINER) compose -f integration.docker-compose.yaml up --force-recreate -d
Expand Down
3 changes: 3 additions & 0 deletions internal/testing/backend/README.md
Expand Up @@ -16,6 +16,9 @@ Also, these tests run in CI. See the "CI for integration tests" job in
All the files here must use the `//go:build integration` tag, so they are not
run with normal unit tests.

To run a single test, use something like: `go test -v --tags=integration -run
TestHasSBOM`

## Writing more tests

* Write normal go test functions. For example
Expand Down
106 changes: 106 additions & 0 deletions internal/testing/backend/artifact_test.go
@@ -0,0 +1,106 @@
//
// Copyright 2023 The GUAC Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integration

package backend_test

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func TestArtifacts(t *testing.T) {
ctx := context.Background()
b := setupTest(t)
tests := []struct {
name string
artifactInput *model.ArtifactInputSpec
artifactSpec *model.ArtifactSpec
idInFilter bool
want []*model.Artifact
wantErr bool
}{{
name: "sha256",
artifactInput: &model.ArtifactInputSpec{
Algorithm: "sha256",
Digest: "6bbb0da1891646e58eb3e6a63af3a6fc3c8eb5a0d44824cba581d2e14a0450cf",
},
artifactSpec: &model.ArtifactSpec{
Algorithm: ptrfrom.String("sha256"),
Digest: ptrfrom.String("6bbb0da1891646e58eb3e6a63af3a6fc3c8eb5a0d44824cba581d2e14a0450cf"),
},
want: []*model.Artifact{{
Algorithm: "sha256",
Digest: "6bbb0da1891646e58eb3e6a63af3a6fc3c8eb5a0d44824cba581d2e14a0450cf",
}},
wantErr: false,
}, {
name: "sha1",
artifactInput: &model.ArtifactInputSpec{
Algorithm: "sha1",
Digest: "7A8F47318E4676DACB0142AFA0B83029CD7BEFD9",
},
artifactSpec: &model.ArtifactSpec{
Algorithm: ptrfrom.String("sha1"),
Digest: ptrfrom.String("7A8F47318E4676DACB0142AFA0B83029CD7BEFD9"),
},
want: []*model.Artifact{{
Algorithm: "sha1",
Digest: "7a8f47318e4676dacb0142afa0b83029cd7befd9",
}},
wantErr: false,
}, {
name: "sha512",
artifactInput: &model.ArtifactInputSpec{
Algorithm: "sha512",
Digest: "374AB8F711235830769AA5F0B31CE9B72C5670074B34CB302CDAFE3B606233EE92EE01E298E5701F15CC7087714CD9ABD7DDB838A6E1206B3642DE16D9FC9DD7",
},
artifactSpec: &model.ArtifactSpec{
Algorithm: ptrfrom.String("sha512"),
Digest: ptrfrom.String("374AB8F711235830769AA5F0B31CE9B72C5670074B34CB302CDAFE3B606233EE92EE01E298E5701F15CC7087714CD9ABD7DDB838A6E1206B3642DE16D9FC9DD7"),
},
idInFilter: true,
want: []*model.Artifact{{
Algorithm: "sha512",
Digest: "374ab8f711235830769aa5f0b31ce9b72c5670074b34cb302cdafe3b606233ee92ee01e298e5701f15cc7087714cd9abd7ddb838a6e1206b3642de16d9fc9dd7",
}},
wantErr: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ingestedArtID, err := b.IngestArtifact(ctx, tt.artifactInput)
if (err != nil) != tt.wantErr {
t.Errorf("arangoClient.IngestArtifact() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.idInFilter {
tt.artifactSpec.ID = ptrfrom.String(ingestedArtID)
}
got, err := b.Artifacts(ctx, tt.artifactSpec)
if (err != nil) != tt.wantErr {
t.Errorf("arangoClient.Artifacts() error = %v, wantErr %v", err, tt.wantErr)
return
}
if diff := cmp.Diff(tt.want, got, commonOpts); diff != "" {
t.Errorf("Unexpected results. (-want +got):\n%s", diff)
}
})
}
}
97 changes: 97 additions & 0 deletions internal/testing/backend/builder_test.go
@@ -0,0 +1,97 @@
//
// Copyright 2023 The GUAC Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integration

package backend_test

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func TestBuilders(t *testing.T) {
ctx := context.Background()
b := setupTest(t)
tests := []struct {
name string
builderInput *model.BuilderInputSpec
builderSpec *model.BuilderSpec
idInFilter bool
want []*model.Builder
wantErr bool
}{{
name: "HubHostedActions",
builderInput: &model.BuilderInputSpec{
URI: "https://github.com/CreateFork/HubHostedActions@v1",
},
builderSpec: &model.BuilderSpec{
URI: ptrfrom.String("https://github.com/CreateFork/HubHostedActions@v1"),
},
want: []*model.Builder{{
URI: "https://github.com/CreateFork/HubHostedActions@v1",
}},
wantErr: false,
}, {
name: "chains",
builderInput: &model.BuilderInputSpec{
URI: "https://tekton.dev/chains/v2",
},
builderSpec: &model.BuilderSpec{
URI: ptrfrom.String("https://tekton.dev/chains/v2"),
},
idInFilter: true,
want: []*model.Builder{{
URI: "https://tekton.dev/chains/v2",
}},
wantErr: false,
}, {
name: "query all",
builderInput: &model.BuilderInputSpec{
URI: "https://tekton.dev/chains/v2",
},
builderSpec: &model.BuilderSpec{},
want: []*model.Builder{{
URI: "https://github.com/CreateFork/HubHostedActions@v1",
}, {
URI: "https://tekton.dev/chains/v2",
}},
wantErr: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ingestedBuilderID, err := b.IngestBuilder(ctx, tt.builderInput)
if (err != nil) != tt.wantErr {
t.Errorf("arangoClient.IngestBuilder() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.idInFilter {
tt.builderSpec.ID = &ingestedBuilderID
}
got, err := b.Builders(ctx, tt.builderSpec)
if (err != nil) != tt.wantErr {
t.Errorf("demoClient.Builders() error = %v, wantErr %v", err, tt.wantErr)
return
}
if diff := cmp.Diff(tt.want, got, commonOpts); diff != "" {
t.Errorf("Unexpected results. (-want +got):\n%s", diff)
}
})
}
}

0 comments on commit c628147

Please sign in to comment.