mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-24 04:06:42 +08:00
test: skip audio tests if ffmpeg is not installed; update expected token value
This commit is contained in:
parent
4076e637fd
commit
92774271b3
@ -5,12 +5,19 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetAudioDuration(t *testing.T) {
|
func TestGetAudioDuration(t *testing.T) {
|
||||||
|
// skip if there is no ffmpeg installed
|
||||||
|
_, err := exec.LookPath("ffmpeg")
|
||||||
|
if err != nil {
|
||||||
|
t.Skip("ffmpeg not installed, skipping test")
|
||||||
|
}
|
||||||
|
|
||||||
t.Run("should return correct duration for a valid audio file", func(t *testing.T) {
|
t.Run("should return correct duration for a valid audio file", func(t *testing.T) {
|
||||||
tmpFile, err := os.CreateTemp("", "test_audio*.mp3")
|
tmpFile, err := os.CreateTemp("", "test_audio*.mp3")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -37,6 +44,12 @@ func TestGetAudioDuration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAudioTokens(t *testing.T) {
|
func TestGetAudioTokens(t *testing.T) {
|
||||||
|
// skip if there is no ffmpeg installed
|
||||||
|
_, err := exec.LookPath("ffmpeg")
|
||||||
|
if err != nil {
|
||||||
|
t.Skip("ffmpeg not installed, skipping test")
|
||||||
|
}
|
||||||
|
|
||||||
t.Run("should return correct tokens for a valid audio file", func(t *testing.T) {
|
t.Run("should return correct tokens for a valid audio file", func(t *testing.T) {
|
||||||
// download test audio file
|
// download test audio file
|
||||||
resp, err := http.Get("https://s3.laisky.com/uploads/2025/01/audio-sample.m4a")
|
resp, err := http.Get("https://s3.laisky.com/uploads/2025/01/audio-sample.m4a")
|
||||||
@ -45,7 +58,7 @@ func TestGetAudioTokens(t *testing.T) {
|
|||||||
|
|
||||||
tokens, err := GetAudioTokens(context.Background(), resp.Body, 50)
|
tokens, err := GetAudioTokens(context.Background(), resp.Body, 50)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, tokens, 200)
|
require.Equal(t, tokens, 195.2)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should return an error for a non-existent file", func(t *testing.T) {
|
t.Run("should return an error for a non-existent file", func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user