Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 89 additions & 6 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: echo "Artifact ID from previous job is $COV_FILE_ID"

- name: Checkout source code for this repository
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # ratchet:actions/checkout@v5
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # ratchet:actions/checkout@v5

- name: Install Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # ratchet:actions/setup-go@v5
Expand All @@ -60,7 +60,7 @@ jobs:
printf 'Coverage Value: %s\n' "$current_coverage"

- name: Download Main Coverage
uses: actions/download-artifact@v8
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # ratchet:actions/download-artifact@v8
with:
artifact-ids: ${{ needs.call-run-upload-main-coverage-files.outputs.coverage-artifact-id }}
path: tmp/
Expand All @@ -87,9 +87,11 @@ jobs:
integration-test-pg:
name: Run integration tests (pg)
runs-on: ubuntu-latest
permissions:
contents: read
services:
postgres:
image: postgres:18
image: index.docker.io/library/postgres@sha256:06cad38a5d9f5d24b4d83d86def30795d5e4b757fedbf5281172b576dedcd941 # ratchet:postgres:18
Comment thread
urangel marked this conversation as resolved.
env:
POSTGRES_USER: dawgs
POSTGRES_PASSWORD: weneedbetterpasswords
Expand All @@ -103,7 +105,9 @@ jobs:
--health-retries 5
steps:
- name: Checkout source code for this repository
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # ratchet:actions/checkout@v5
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # ratchet:actions/checkout@v5
with:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # ratchet:actions/setup-go@v5
Expand All @@ -121,9 +125,11 @@ jobs:
integration-test-neo4j:
name: Run integration tests (neo4j)
runs-on: ubuntu-latest
permissions:
contents: read
services:
neo4j:
image: neo4j:4.4.42
image: index.docker.io/library/neo4j@sha256:73b5a47eb9952f47fcc42fcc80bdd6bd0d6b71eea9a1a345c216675498c790e4 # ratchet:neo4j:4.4.42
env:
NEO4J_AUTH: neo4j/weneedbetterpasswords
ports:
Expand All @@ -136,7 +142,9 @@ jobs:
--health-start-period 40s
steps:
- name: Checkout source code for this repository
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # ratchet:actions/checkout@v5
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # ratchet:actions/checkout@v5
with:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # ratchet:actions/setup-go@v5
Expand All @@ -150,3 +158,78 @@ jobs:
CONNECTION_STRING: neo4j://neo4j:weneedbetterpasswords@localhost:7687
run: |
make test_integration

bdd-integration-test-pg:
name: Run BDD integration tests (pg)
runs-on: ubuntu-latest
permissions:
contents: read
services:
postgres:
image: index.docker.io/library/postgres@sha256:06cad38a5d9f5d24b4d83d86def30795d5e4b757fedbf5281172b576dedcd941 # ratchet:postgres:18
env:
POSTGRES_USER: dawgs
POSTGRES_PASSWORD: weneedbetterpasswords
POSTGRES_DB: dawgs
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U dawgs -d dawgs"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout source code for this repository
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # ratchet:actions/checkout@v5
with:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # ratchet:actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
check-latest: true

- name: Run BDD integration tests
env:
CONNECTION_STRING: postgres://dawgs:weneedbetterpasswords@localhost:5432/dawgs?sslmode=disable
run: |
make test_bdd_integration

bdd-integration-test-neo4j:
name: Run BDD integration tests (neo4j)
runs-on: ubuntu-latest
permissions:
contents: read
services:
neo4j:
image: index.docker.io/library/neo4j@sha256:73b5a47eb9952f47fcc42fcc80bdd6bd0d6b71eea9a1a345c216675498c790e4 # ratchet:neo4j:4.4.42
env:
NEO4J_AUTH: neo4j/weneedbetterpasswords
ports:
- 7687:7687
options: >-
--health-cmd "wget -q -O /dev/null http://localhost:7474 || exit 1"
--health-interval 15s
--health-timeout 10s
--health-retries 10
--health-start-period 40s
steps:
- name: Checkout source code for this repository
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # ratchet:actions/checkout@v5
with:
persist-credentials: false

- name: Install Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # ratchet:actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
check-latest: true

- name: Run BDD integration tests
env:
CONNECTION_STRING: neo4j://neo4j:weneedbetterpasswords@localhost:7687
run: |
make test_bdd_integration
Comment thread
coderabbitai[bot] marked this conversation as resolved.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QUALITY_INPUTS += -mutation-report $(MUTATION_REPORT)
endif
QUALITY_INPUTS += -benchmark-regression $(BENCHMARK_REGRESSION)

.PHONY: default all build deps tidy lint format test test_all test_integration test_neo4j test_pg test_update plan_corpus complexity complexity_check crap crap_check quality quality_check quality_backend quality_bench metrics metrics_check generate clean help
.PHONY: default all build deps tidy lint format test test_all test_integration test_bdd_integration test_neo4j test_pg test_update plan_corpus complexity complexity_check crap crap_check quality quality_check quality_backend quality_bench metrics metrics_check generate clean help

# Default target
default: help
Expand Down Expand Up @@ -92,12 +92,14 @@ test: $(METRICS_DIR)
@$(GO_CMD) tool cover -func=$(COVERAGE_PROFILE) > $(COVERAGE_FUNC_REPORT)
@echo "Coverage report written to $(COVERAGE_FUNC_REPORT)"

test_all: test test_integration
test_all: test test_integration test_bdd_integration

test_integration:
@echo "Running all integration tests..."
@$(GO_CMD) test -tags 'manual_integration integration' -race -cover -count=1 -p=1 -parallel=1 $(MAIN_PACKAGES)

test_bdd_integration:
@echo "Running all BDD integration tests..."
@$(GO_CMD) test -v -tags 'bdd_integration' -count=1 ./bdd
test_bench:
@echo "Running benchmarks..."
@$(GO_CMD) test -run '^$$' -bench '$(BENCH)' -benchmem -count=$(BENCH_COUNT) -benchtime=$(BENCH_TIME) $(MAIN_PACKAGES)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ make test

Run integration tests when a backend is available:

Export the `CONNECTION_STRING` environment variable for the PostgreSQL or Neo4j driver.

```bash
export CONNECTION_STRING="postgresql://dawgs:weneedbetterpasswords@localhost:65432/dawgs"
make test_integration
```

```bash
export CONNECTION_STRING="postgresql://dawgs:weneedbetterpasswords@localhost:65432/dawgs"
make test_bdd_integration
```
Comment thread
ykaiboussiSO marked this conversation as resolved.

Use this module from another Go project:

```bash
Expand Down
28 changes: 28 additions & 0 deletions bdd/features/matching.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Match nodes

Scenario: Match non existed nodes
Given an empty graph
When executing query:
"""
MATCH (n)
RETURN n
"""
Then the result should be:
| n |

Scenario: Matching all nodes
Given an empty graph
And having executed:
"""
CREATE (:A), (:B {prefix: 'c', name: 'b'}), ({name: 'c'})
"""
When executing query:
"""
MATCH (n)
RETURN n
"""
Then the result should be:
| n |
| (:A) |
| (:B{name: 'b', prefix: 'c'}) |
| ({name: 'c'}) |
84 changes: 84 additions & 0 deletions bdd/steps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2026 Specter Ops, Inc.
//
// Licensed under the Apache License, Version 2.0
// 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.
//
// SPDX-License-Identifier: Apache-2.0
//

//go:build bdd_integration

package bdd

import (
"context"
"log"
"testing"

"github.com/cucumber/godog"
"github.com/specterops/dawgs/graph"
"github.com/specterops/dawgs/integration"
)

func InitializeTestSuite(ctxtestsuite *godog.TestSuiteContext, ctx context.Context, c *dbContext) {
err := c.db.WriteTransaction(ctx, func(tx graph.Transaction) error {
if err := tx.Nodes().Delete(); err != nil {
return err
}
return nil
})
if err != nil {
log.Fatalf("Failed to clear database %v", err)
}
}

func InitializeScenario(ctx *godog.ScenarioContext, dbCtx *dbContext) {
ctx.Step(`^an empty graph$`, dbCtx.anEmptyGraph)
ctx.Step(`^having executed:$`, dbCtx.havingExecuted)
ctx.Step(`^executing query:$`, dbCtx.executingQuery)
ctx.Step(`^the result should be:$`, dbCtx.theResultShouldBe)
}

func TestFeatures(t *testing.T) {
backgroundCtx := context.Background()
// establish database connection
session := integration.Open(t, integration.Options{
Schema: &graph.Schema{
DefaultGraph: graph.Graph{
Name: "dawgs-bdd",
},
},
})

dbCtx := &dbContext{
db: session.DB,
}
suite := godog.TestSuite{
Name: "OpenCypher-TCK",
TestSuiteInitializer: func(ctx *godog.TestSuiteContext) {
InitializeTestSuite(ctx, backgroundCtx, dbCtx)
},
ScenarioInitializer: func(ctx *godog.ScenarioContext) {
InitializeScenario(ctx, dbCtx)
},
Options: &godog.Options{
Format: "pretty",
// TODO create env variable pointing to the TCK features via CI
Paths: []string{"features"},
TestingT: t,
},
}

if num := suite.Run(); num != 0 {
t.Fatalf("TestSuite execution failed with status %d", num)
}
}
Loading
Loading