Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
70
backend/internal/translator/common/responses_test.go
Normal file
70
backend/internal/translator/common/responses_test.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestSetResponsesToolCallIdentity(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
toolName string
|
||||
namespace string
|
||||
itemPath string
|
||||
namePath string
|
||||
namespacePath string
|
||||
wantName string
|
||||
wantNamespace string
|
||||
wantNamespaceExists bool
|
||||
}{
|
||||
{
|
||||
name: "top level",
|
||||
input: `{"name":"functions__exec"}`,
|
||||
toolName: "exec",
|
||||
namespace: "functions",
|
||||
namePath: "name",
|
||||
namespacePath: "namespace",
|
||||
wantName: "exec",
|
||||
wantNamespace: "functions",
|
||||
wantNamespaceExists: true,
|
||||
},
|
||||
{
|
||||
name: "nested item",
|
||||
input: `{"item":{"name":"functions__exec"}}`,
|
||||
toolName: "exec",
|
||||
namespace: "functions",
|
||||
itemPath: "item",
|
||||
namePath: "item.name",
|
||||
namespacePath: "item.namespace",
|
||||
wantName: "exec",
|
||||
wantNamespace: "functions",
|
||||
wantNamespaceExists: true,
|
||||
},
|
||||
{
|
||||
name: "remove stale namespace",
|
||||
input: `{"name":"old","namespace":"stale"}`,
|
||||
toolName: "plain",
|
||||
namePath: "name",
|
||||
namespacePath: "namespace",
|
||||
wantName: "plain",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := SetResponsesToolCallIdentity([]byte(test.input), test.toolName, test.namespace, test.itemPath)
|
||||
if actual := gjson.GetBytes(got, test.namePath).String(); actual != test.wantName {
|
||||
t.Fatalf("name = %q, want %q; output=%s", actual, test.wantName, got)
|
||||
}
|
||||
namespace := gjson.GetBytes(got, test.namespacePath)
|
||||
if namespace.Exists() != test.wantNamespaceExists {
|
||||
t.Fatalf("namespace exists = %t, want %t; output=%s", namespace.Exists(), test.wantNamespaceExists, got)
|
||||
}
|
||||
if test.wantNamespaceExists && namespace.String() != test.wantNamespace {
|
||||
t.Fatalf("namespace = %q, want %q; output=%s", namespace.String(), test.wantNamespace, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue