-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a single backend acceptance test suite. (#1597)
* Create a single backend acceptance test suite. A new integration test suite is added under internal/testing/backend to test all backends with the same set of tests. All the test scaffolding is seutp to run all the backends. Only "CertifyBad" tests have been copied in in this first commit. Signed-off-by: Jeff Mendoza <[email protected]> * Fix typo Signed-off-by: Mihai Maruseac <[email protected]> Signed-off-by: Mihai Maruseac <[email protected]> --------- Signed-off-by: Jeff Mendoza <[email protected]> Signed-off-by: Mihai Maruseac <[email protected]> Signed-off-by: Mihai Maruseac <[email protected]> Co-authored-by: Mihai Maruseac <[email protected]>
- Loading branch information
1 parent
545e294
commit c5d84b6
Showing
37 changed files
with
1,857 additions
and
106 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
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,51 @@ | ||
# GUAC Backend Acceptance Test Suite | ||
|
||
## How to run | ||
|
||
Run all the backend containers using the compose yaml and then run the tests: | ||
|
||
```shell | ||
cd internal/testing/backend | ||
docker-compose up -d | ||
go test -v --tags=integration . | ||
``` | ||
|
||
Also, these tests run in CI. See the "CI for integration tests" job in | ||
[ci.yaml](/.github/workflows/ci.yaml) | ||
|
||
All the files here must use the `//go:build integration` tag, so they are not | ||
run with normal unit tests. | ||
|
||
## Writing more tests | ||
|
||
* Write normal go test functions. For example | ||
`func TestMytestname(t *testing.T) {`. These will be executed multiple times, | ||
once for each backend. | ||
|
||
* Tests should receive a `backends.Backend` object by calling | ||
`setupTest(t)`. All testing is done on the received backend. | ||
|
||
* Use `github.com/google/go-cmp/cmp` to compare expected and recieved | ||
values. The `commonOpts` global is used for any `Diff()` calls to that | ||
library. Add any needed options to that global in `setupOpts()`. | ||
|
||
* Use `/internal/testing/testdata` for any test node data. | ||
|
||
* Put any simple test data in `helpers_test.go` for reuse, such as `curTime`. | ||
|
||
## Adding a backend | ||
|
||
* Create a new `<name>_test.go` file and implement the `backend` interface. | ||
|
||
* In [main_test.go](main_test.go): | ||
|
||
* Add a new global string to name the backend. | ||
|
||
* Add the backend to the `testBackends` map, with a constructor for the | ||
`backend` interface. | ||
|
||
* Add any needed skips to the `skipMatrix` map, if the new backend does not | ||
support all the node types yet. | ||
|
||
* Before submitting, update this [docker-compose.yaml](docker-compose.yaml) to start any | ||
external dependencies needed. |
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,66 @@ | ||
// | ||
// 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" | ||
|
||
"github.com/guacsec/guac/pkg/assembler/backends" | ||
"github.com/guacsec/guac/pkg/assembler/backends/arangodb" | ||
) | ||
|
||
type arangoBE struct { | ||
be backends.Backend | ||
args *arangodb.ArangoConfig | ||
} | ||
|
||
func newArango() backend { | ||
return &arangoBE{ | ||
args: &arangodb.ArangoConfig{ | ||
User: "root", | ||
Pass: "test123", | ||
DBAddr: "http://localhost:8529", | ||
}, | ||
} | ||
} | ||
|
||
func (m *arangoBE) Setup() error { | ||
if err := arangodb.DeleteDatabase(context.Background(), m.args); err != nil { | ||
return err | ||
} | ||
be, err := backends.Get("arango", context.Background(), m.args) | ||
m.be = be | ||
return err | ||
} | ||
|
||
func (m *arangoBE) Get() backends.Backend { | ||
return m.be | ||
} | ||
|
||
func (m *arangoBE) Clear() error { | ||
if err := arangodb.DeleteDatabase(context.Background(), m.args); err != nil { | ||
return err | ||
} | ||
// For some reason, need to call Get again after delete | ||
be, err := backends.Get("arango", context.Background(), m.args) | ||
m.be = be | ||
return err | ||
} | ||
|
||
func (m *arangoBE) Cleanup() { | ||
} |
Oops, something went wrong.