From 92774271b3849176022caf01b5e666bfcdcef376 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Sun, 9 Mar 2025 12:59:37 +0000 Subject: [PATCH] test: skip audio tests if ffmpeg is not installed; update expected token value --- common/helper/audio_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/helper/audio_test.go b/common/helper/audio_test.go index 15f55bbb..2fdede4d 100644 --- a/common/helper/audio_test.go +++ b/common/helper/audio_test.go @@ -5,12 +5,19 @@ import ( "io" "net/http" "os" + "os/exec" "testing" "github.com/stretchr/testify/require" ) 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) { tmpFile, err := os.CreateTemp("", "test_audio*.mp3") require.NoError(t, err) @@ -37,6 +44,12 @@ func TestGetAudioDuration(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) { // download test audio file 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) 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) {