Skip to content

Commit 80f7885

Browse files
Integrate Go driver examples into automated build process
- Add examples execution to gremlin-go-integration-tests container - Make server URLs configurable via environment variables - Use specialized labels (person-go-ex, go-conn-ex) to isolate test data - Build fails if any example fails to execute - Replace port placeholder logic with getEnvOrDefaultString() helper - Use configurable vertex labels in examples
1 parent de99ce6 commit 80f7885

File tree

5 files changed

+69
-28
lines changed

5 files changed

+69
-28
lines changed

glv-examples/gremlin-go/connections.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func withRemote() {
5151
<-prom
5252

5353
// Simple query to verify connection
54-
g.AddV().Iterate()
55-
count, _ := g.V().Count().Next()
54+
g.AddV("connection").Iterate()
55+
count, _ := g.V().HasLabel("connection").Count().Next()
5656
fmt.Println("Vertex count:", *count)
5757
}
5858

@@ -75,7 +75,7 @@ func withConfigs() {
7575
defer driverRemoteConnection.Close()
7676
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
7777

78-
g.AddV().Iterate()
79-
count, _ := g.V().Count().Next()
78+
g.AddV("connection").Iterate()
79+
count, _ := g.V().HasLabel("connection").Count().Next()
8080
fmt.Println("Vertex count:", *count)
8181
}

gremlin-go/docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,16 @@ services:
6060
- RUN_BASIC_AUTH_INTEGRATION_TESTS=true
6161
- GREMLIN_SOCKET_SERVER_URL=ws://gremlin-socket-server-go
6262
- GREMLIN_SOCKET_SERVER_CONFIG_PATH=/go_app/gremlin-socket-server/conf/test-ws-gremlin.yaml
63+
- VERTEX_LABEL=go-example
6364
working_dir: /go_app
6465
command: >
6566
bash -c "go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
66-
&& go test -v -json ./... -race -covermode=atomic -coverprofile=\"coverage.out\" -coverpkg=./... | gotestfmt"
67+
&& go test -v -json ./... -race -covermode=atomic -coverprofile=\"coverage.out\" -coverpkg=./... | gotestfmt
68+
&& echo 'Running examples...'
69+
&& go run examples/basic_gremlin.go
70+
&& go run examples/connections.go
71+
&& go run examples/modern_traversals.go
72+
&& echo 'All examples completed successfully'"
6773
depends_on:
6874
gremlin-server-test:
6975
condition: service_healthy

gremlin-go/examples/basic_gremlin.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ package main
2121

2222
import (
2323
"fmt"
24+
"os"
2425

2526
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
2627
)
2728

29+
func getEnvOrDefaultString(key string, defaultValue string) string {
30+
value := os.Getenv(key)
31+
if len(value) != 0 {
32+
return value
33+
}
34+
return defaultValue
35+
}
36+
2837
func main() {
29-
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
38+
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
39+
vertexLabel := getEnvOrDefaultString("VERTEX_LABEL", "person")
40+
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
3041
if err != nil {
3142
fmt.Println(err)
3243
return
@@ -35,9 +46,9 @@ func main() {
3546
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
3647

3748
// Basic Gremlin: adding and retrieving data
38-
v1, err := g.AddV("person").Property("name", "marko").Next()
39-
v2, err := g.AddV("person").Property("name", "stephen").Next()
40-
v3, err := g.AddV("person").Property("name", "vadas").Next()
49+
v1, err := g.AddV(vertexLabel).Property("name", "marko").Next()
50+
v2, err := g.AddV(vertexLabel).Property("name", "stephen").Next()
51+
v3, err := g.AddV(vertexLabel).Property("name", "vadas").Next()
4152
v1Vertex, err := v1.GetVertex()
4253
v2Vertex, err := v2.GetVertex()
4354
v3Vertex, err := v3.GetVertex()
@@ -58,12 +69,12 @@ func main() {
5869
}
5970

6071
// Retrieve the data from the "marko" vertex
61-
marko, err := g.V().Has("person", "name", "marko").Values("name").Next()
72+
marko, err := g.V().Has(vertexLabel, "name", "marko").Values("name").Next()
6273
fmt.Println("name:", marko.GetString())
6374

6475
// Find the "marko" vertex and then traverse to the people he "knows" and return their data
65-
peopleMarkoKnows, err := g.V().Has("person", "name", "marko").Out("knows").Values("name").ToList()
76+
peopleMarkoKnows, err := g.V().Has(vertexLabel, "name", "marko").Out("knows").Values("name").ToList()
6677
for _, person := range peopleMarkoKnows {
6778
fmt.Println("marko knows", person.GetString())
6879
}
69-
}
80+
}

gremlin-go/examples/connections.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,30 @@ package main
2121

2222
import (
2323
"fmt"
24+
"os"
2425

2526
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
2627
)
2728

29+
func getEnvOrDefaultString(key string, defaultValue string) string {
30+
value := os.Getenv(key)
31+
if len(value) != 0 {
32+
return value
33+
}
34+
return defaultValue
35+
}
36+
2837
func main() {
2938
withRemote()
3039
withConfigs()
3140
}
3241

3342
func withRemote() {
34-
// Creating the connection to the server
35-
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
43+
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
44+
vertexLabel := getEnvOrDefaultString("VERTEX_LABEL", "connection")
45+
46+
// Creating the connection to the server
47+
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
3648

3749
// Error handling
3850
if err != nil {
@@ -43,22 +55,24 @@ func withRemote() {
4355
// Cleanup
4456
defer driverRemoteConnection.Close()
4557

46-
// Creating the graph traversal
58+
// Creating the graph traversal
4759
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
4860

49-
// Drop existing vertices
50-
prom := g.V().Drop().Iterate()
51-
<-prom
61+
// Simple query to verify connection
62+
g.AddV(vertexLabel).Iterate()
63+
count, _ := g.V().Count().Next()
64+
fmt.Println("Vertex count:", *count)
5265

53-
// Simple query to verify connection
54-
g.AddV().Iterate()
55-
count, _ := g.V().Count().Next()
56-
fmt.Println("Vertex count:", *count)
66+
// clean added data
67+
g.V().HasLabel(vertexLabel).Drop().Iterate()
5768
}
5869

5970
func withConfigs() {
71+
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
72+
vertexLabel := getEnvOrDefaultString("VERTEX_LABEL", "connection")
73+
6074
// Connecting to the server with customized configurations
61-
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin",
75+
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL,
6276
func(settings *gremlingo.DriverRemoteConnectionSettings) {
6377
settings.TraversalSource = "g"
6478
settings.NewConnectionThreshold = 4
@@ -75,7 +89,7 @@ func withConfigs() {
7589
defer driverRemoteConnection.Close()
7690
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
7791

78-
g.AddV().Iterate()
79-
count, _ := g.V().Count().Next()
80-
fmt.Println("Vertex count:", *count)
81-
}
92+
g.AddV(vertexLabel).Iterate()
93+
count, _ := g.V().Count().Next()
94+
fmt.Println("Vertex count:", *count)
95+
}

gremlin-go/examples/modern_traversals.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package main
2121

2222
import (
2323
"fmt"
24+
"os"
2425

2526
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
2627
)
@@ -29,8 +30,17 @@ var __ = gremlingo.T__
2930
var T = gremlingo.T
3031
var P = gremlingo.P
3132

33+
func getEnvOrDefaultString(key string, defaultValue string) string {
34+
value := os.Getenv(key)
35+
if len(value) != 0 {
36+
return value
37+
}
38+
return defaultValue
39+
}
40+
3241
func main() {
33-
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
42+
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
43+
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
3444
if err != nil {
3545
fmt.Println(err)
3646
return

0 commit comments

Comments
 (0)