render_template_test.go 994 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package plugin
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
  6. )
  7. func TestRenderPythonToolTemplate(t *testing.T) {
  8. manifest := &plugin_entities.PluginDeclaration{
  9. PluginDeclarationWithoutAdvancedFields: plugin_entities.PluginDeclarationWithoutAdvancedFields{
  10. Name: "test",
  11. Author: "test",
  12. Description: plugin_entities.I18nObject{
  13. EnUS: "test",
  14. },
  15. },
  16. }
  17. content, err := renderTemplate(PYTHON_TOOL_PY_TEMPLATE, manifest, []string{""})
  18. if err != nil {
  19. t.Errorf("failed to render template: %v", err)
  20. }
  21. if !strings.Contains(content, "TestTool") {
  22. t.Errorf("template content does not contain TestTool, snakeToCamel failed")
  23. }
  24. content, err = renderTemplate(PYTHON_TOOL_PROVIDER_TEMPLATE, manifest, []string{""})
  25. if err != nil {
  26. t.Errorf("failed to render template: %v", err)
  27. }
  28. if !strings.Contains(content, "test") {
  29. t.Errorf("template content does not contain TestTool, snakeToCamel failed")
  30. }
  31. }