Skip to content

Commit

Permalink
Add basic integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyeats committed Mar 19, 2024
1 parent b14df58 commit a4405c5
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions e2e/datasource/integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package integration_test

import (
"context"
"encoding/json"
"os"
"testing"

"github.com/grafana-labs/surrealdb-datasource/pkg/client"
"github.com/grafana-labs/surrealdb-datasource/pkg/plugin"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)

func getEndpoint() string {
if os.Getenv("CI") != "true" {
return "ws://localhost:8000/rpc"
}

return "ws://surrealdb:8000/rpc"
}

// @TODO: Move this test to an integration test suite.
func TestIntegration(t *testing.T) {
config := client.SurrealConfig{
Database: "test",
Endpoint: getEndpoint(),
Namespace: "test",
Username: "root",
}

msg, err := json.Marshal(config)

if err != nil {
t.Errorf("unexpected error: %s", err)
}

dsiConfig := backend.DataSourceInstanceSettings{
JSONData: msg,
DecryptedSecureJSONData: map[string]string{"password": "test"},
}

instance, err := plugin.NewDatasource(context.Background(), dsiConfig)

if err != nil {
t.Errorf("unexpected error: %s", err)
}
if instance == nil {
t.Error("expected instance to be non-nil")
}
}

0 comments on commit a4405c5

Please sign in to comment.