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
110 changes: 0 additions & 110 deletions tests/alloydb/alloydb_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"regexp"
"sort"
Expand All @@ -37,115 +36,6 @@ import (
"github.com/googleapis/genai-toolbox/tests"
)

var (
AlloyDBProject = os.Getenv("ALLOYDB_PROJECT")
AlloyDBLocation = os.Getenv("ALLOYDB_REGION")
AlloyDBCluster = os.Getenv("ALLOYDB_CLUSTER")
AlloyDBInstance = os.Getenv("ALLOYDB_INSTANCE")
AlloyDBUser = os.Getenv("ALLOYDB_POSTGRES_USER")
)

func getAlloyDBVars(t *testing.T) map[string]string {
if AlloyDBProject == "" {
t.Fatal("'ALLOYDB_PROJECT' not set")
}
if AlloyDBLocation == "" {
t.Fatal("'ALLOYDB_REGION' not set")
}
if AlloyDBCluster == "" {
t.Fatal("'ALLOYDB_CLUSTER' not set")
}
if AlloyDBInstance == "" {
t.Fatal("'ALLOYDB_INSTANCE' not set")
}
if AlloyDBUser == "" {
t.Fatal("'ALLOYDB_USER' not set")
}
return map[string]string{
"project": AlloyDBProject,
"location": AlloyDBLocation,
"cluster": AlloyDBCluster,
"instance": AlloyDBInstance,
"user": AlloyDBUser,
}
}

func getAlloyDBToolsConfig() map[string]any {
return map[string]any{
"sources": map[string]any{
"alloydb-admin-source": map[string]any{
"type": "alloydb-admin",
},
},
"tools": map[string]any{
// Tool for RunAlloyDBToolGetTest
"my-simple-tool": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Simple tool to test end to end functionality.",
},
// Tool for MCP test
"my-param-tool": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Tool to list clusters",
},
// Tool for MCP test that fails
"my-fail-tool": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Tool that will fail",
},
// AlloyDB specific tools
"alloydb-list-clusters": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Lists all AlloyDB clusters in a given project and location.",
},
"alloydb-list-users": map[string]any{
"type": "alloydb-list-users",
"source": "alloydb-admin-source",
"description": "Lists all AlloyDB users within a specific cluster.",
},
"alloydb-list-instances": map[string]any{
"type": "alloydb-list-instances",
"source": "alloydb-admin-source",
"description": "Lists all AlloyDB instances within a specific cluster.",
},
"alloydb-get-cluster": map[string]any{
"type": "alloydb-get-cluster",
"source": "alloydb-admin-source",
"description": "Retrieves details of a specific AlloyDB cluster.",
},
"alloydb-get-instance": map[string]any{
"type": "alloydb-get-instance",
"source": "alloydb-admin-source",
"description": "Retrieves details of a specific AlloyDB instance.",
},
"alloydb-get-user": map[string]any{
"type": "alloydb-get-user",
"source": "alloydb-admin-source",
"description": "Retrieves details of a specific AlloyDB user.",
},
"alloydb-create-cluster": map[string]any{
"type": "alloydb-create-cluster",
"description": "create cluster",
"source": "alloydb-admin-source",
},
"alloydb-create-instance": map[string]any{
"type": "alloydb-create-instance",
"description": "create instance",
"source": "alloydb-admin-source",
},
"alloydb-create-user": map[string]any{
"type": "alloydb-create-user",
"description": "create user",
"source": "alloydb-admin-source",
},
},
}
}

func TestAlloyDBToolEndpoints(t *testing.T) {
vars := getAlloyDBVars(t)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
Expand Down
119 changes: 113 additions & 6 deletions tests/alloydb/alloydb_mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"regexp"
"sort"
Expand All @@ -33,6 +34,115 @@ import (
"github.com/googleapis/genai-toolbox/tests"
)

var (
AlloyDBProject = os.Getenv("ALLOYDB_PROJECT")
AlloyDBLocation = os.Getenv("ALLOYDB_REGION")
AlloyDBCluster = os.Getenv("ALLOYDB_CLUSTER")
AlloyDBInstance = os.Getenv("ALLOYDB_INSTANCE")
AlloyDBUser = os.Getenv("ALLOYDB_POSTGRES_USER")
)

func getAlloyDBVars(t *testing.T) map[string]string {
if AlloyDBProject == "" {
t.Fatal("'ALLOYDB_PROJECT' not set")
}
if AlloyDBLocation == "" {
t.Fatal("'ALLOYDB_REGION' not set")
}
if AlloyDBCluster == "" {
t.Fatal("'ALLOYDB_CLUSTER' not set")
}
if AlloyDBInstance == "" {
t.Fatal("'ALLOYDB_INSTANCE' not set")
}
if AlloyDBUser == "" {
t.Fatal("'ALLOYDB_USER' not set")
}
return map[string]string{
"project": AlloyDBProject,
"location": AlloyDBLocation,
"cluster": AlloyDBCluster,
"instance": AlloyDBInstance,
"user": AlloyDBUser,
}
}

func getAlloyDBToolsConfig() map[string]any {
return map[string]any{
"sources": map[string]any{
"alloydb-admin-source": map[string]any{
"type": "alloydb-admin",
},
},
"tools": map[string]any{
// Tool for RunAlloyDBToolGetTest
"my-simple-tool": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Simple tool to test end to end functionality.",
},
// Tool for MCP test
"my-param-tool": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Tool to list clusters",
},
// Tool for MCP test that fails
"my-fail-tool": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Tool that will fail",
},
// AlloyDB specific tools
"alloydb-list-clusters": map[string]any{
"type": "alloydb-list-clusters",
"source": "alloydb-admin-source",
"description": "Lists all AlloyDB clusters in a given project and location.",
},
"alloydb-list-users": map[string]any{
"type": "alloydb-list-users",
"source": "alloydb-admin-source",
"description": "Lists all AlloyDB users within a specific cluster.",
},
"alloydb-list-instances": map[string]any{
"type": "alloydb-list-instances",
"source": "alloydb-admin-source",
"description": "Lists all AlloyDB instances within a specific cluster.",
},
"alloydb-get-cluster": map[string]any{
"type": "alloydb-get-cluster",
"source": "alloydb-admin-source",
"description": "Retrieves details of a specific AlloyDB cluster.",
},
"alloydb-get-instance": map[string]any{
"type": "alloydb-get-instance",
"source": "alloydb-admin-source",
"description": "Retrieves details of a specific AlloyDB instance.",
},
"alloydb-get-user": map[string]any{
"type": "alloydb-get-user",
"source": "alloydb-admin-source",
"description": "Retrieves details of a specific AlloyDB user.",
},
"alloydb-create-cluster": map[string]any{
"type": "alloydb-create-cluster",
"description": "create cluster",
"source": "alloydb-admin-source",
},
"alloydb-create-instance": map[string]any{
"type": "alloydb-create-instance",
"description": "create instance",
"source": "alloydb-admin-source",
},
"alloydb-create-user": map[string]any{
"type": "alloydb-create-user",
"description": "create user",
"source": "alloydb-admin-source",
},
},
}
}

func TestAlloyDBListTools(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
Expand Down Expand Up @@ -845,9 +955,8 @@ func TestAlloyDBCreateClusterMCP(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

args := []string{"--enable-api"}
toolsFile := getAlloyDBToolsConfig()
cmd, cleanupCmd, err := tests.StartCmd(ctx, toolsFile, args...)
cmd, cleanupCmd, err := tests.StartCmd(ctx, toolsFile)
if err != nil {
t.Fatalf("command initialization returned an error: %v", err)
}
Expand Down Expand Up @@ -942,9 +1051,8 @@ func TestAlloyDBCreateInstanceMCP(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

args := []string{"--enable-api"}
toolsFile := getAlloyDBToolsConfig()
cmd, cleanupCmd, err := tests.StartCmd(ctx, toolsFile, args...)
cmd, cleanupCmd, err := tests.StartCmd(ctx, toolsFile)
if err != nil {
t.Fatalf("command initialization returned an error: %v", err)
}
Expand Down Expand Up @@ -1049,9 +1157,8 @@ func TestAlloyDBCreateUserMCP(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

args := []string{"--enable-api"}
toolsFile := getAlloyDBToolsConfig()
cmd, cleanupCmd, err := tests.StartCmd(ctx, toolsFile, args...)
cmd, cleanupCmd, err := tests.StartCmd(ctx, toolsFile)
if err != nil {
t.Fatalf("command initialization returned an error: %v", err)
}
Expand Down
Loading
Loading