No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

41 líneas
1.7 KiB

  1. package controller
  2. import (
  3. "testing"
  4. "github.com/QuantumNous/new-api/common"
  5. "github.com/QuantumNous/new-api/model"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestExtractGeminiVideoURLSupportsTopLevelAndNestedShapes(t *testing.T) {
  9. require.Equal(t, "https://video.example/top", extractGeminiVideoURLFromMap(map[string]any{"uri": "https://video.example/top"}))
  10. nested := map[string]any{
  11. "response": map[string]any{
  12. "generateVideoResponse": map[string]any{
  13. "generatedSamples": []any{map[string]any{"video": map[string]any{"uri": "https://video.example/generated"}}},
  14. },
  15. },
  16. }
  17. require.Equal(t, "https://video.example/generated", extractGeminiVideoURLFromMap(nested))
  18. require.Equal(t, "", extractGeminiVideoURLFromMap(map[string]any{"response": map[string]any{}}))
  19. }
  20. func TestExtractGeminiVideoURLFromTaskDataRejectsInvalidJSON(t *testing.T) {
  21. task := &model.Task{Data: []byte("not-json")}
  22. require.Empty(t, extractGeminiVideoURLFromTaskData(task))
  23. payload, err := common.Marshal(map[string]any{"response": map[string]any{"video": "https://video.example/nested"}})
  24. require.NoError(t, err)
  25. task.Data = payload
  26. require.Equal(t, "https://video.example/nested", extractGeminiVideoURLFromTaskData(task))
  27. }
  28. func TestEnsureAPIKeyAppendsOnlyWhenMissing(t *testing.T) {
  29. require.Equal(t, "https://video.example/file?key=abc", ensureAPIKey("https://video.example/file", "abc"))
  30. require.Equal(t, "https://video.example/file?alt=media&key=abc", ensureAPIKey("https://video.example/file?alt=media", "abc"))
  31. require.Equal(t, "https://video.example/file?key=existing", ensureAPIKey("https://video.example/file?key=existing", "abc"))
  32. require.Equal(t, "https://video.example/file", ensureAPIKey("https://video.example/file", ""))
  33. }