43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package handler
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"encoding/json"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestValidateNodeExtractConfigGraphBackend(t *testing.T) {
|
||
|
|
for _, tc := range []struct {
|
||
|
|
name string
|
||
|
|
neo4j string
|
||
|
|
legacy string
|
||
|
|
disabled bool
|
||
|
|
incomplete bool
|
||
|
|
wantErr bool
|
||
|
|
}{
|
||
|
|
{name: "no backend", wantErr: true},
|
||
|
|
{name: "neo4j", neo4j: "true"},
|
||
|
|
{name: "native backend", neo4j: "false", legacy: "true"},
|
||
|
|
{name: "case insensitive native backend", legacy: "TRUE"},
|
||
|
|
{name: "disabled extraction needs no backend", disabled: true},
|
||
|
|
{name: "native backend still validates examples", legacy: "true", incomplete: true, wantErr: true},
|
||
|
|
} {
|
||
|
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
|
t.Setenv("NEO4J_ENABLE", tc.neo4j)
|
||
|
|
t.Setenv("LEGACY_GRAPH_ENABLE", tc.legacy)
|
||
|
|
req := &InitializationRequest{}
|
||
|
|
if err := json.Unmarshal([]byte(`{"nodeExtract":{"text":"Alice knows Bob","tags":["knows"],"nodes":[{"name":"Alice"},{"name":"Bob"}],"relations":[{"node1":"Alice","node2":"Bob","type":"knows"}]}}`), req); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
req.NodeExtract.Enabled = !tc.disabled
|
||
|
|
if tc.incomplete {
|
||
|
|
req.NodeExtract.Relations = nil
|
||
|
|
}
|
||
|
|
err := validateNodeExtractConfig(context.Background(), req)
|
||
|
|
if (err != nil) != tc.wantErr {
|
||
|
|
t.Fatalf("validateNodeExtractConfig() error = %v, wantErr %v", err, tc.wantErr)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|