fix: resolve golangci-lint errcheck warnings
- Add error checks for unchecked return values (errcheck) - Remove unused struct fields (unused) - Fix gofmt formatting issues
This commit is contained in:
48
e2e_test.go
48
e2e_test.go
@@ -24,13 +24,13 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
|||||||
audioSize := 65536
|
audioSize := 65536
|
||||||
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload map[string]any
|
var payload map[string]any
|
||||||
json.NewDecoder(r.Body).Decode(&payload)
|
_ = json.NewDecoder(r.Body).Decode(&payload)
|
||||||
if payload["text"] == nil || payload["text"] == "" {
|
if payload["text"] == nil || payload["text"] == "" {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte("empty text"))
|
_, _ = w.Write([]byte("empty text"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(make([]byte, audioSize))
|
_, _ = w.Write(make([]byte, audioSize))
|
||||||
}))
|
}))
|
||||||
defer xttsSrv.Close()
|
defer xttsSrv.Close()
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
audioBytes, _ := io.ReadAll(resp.Body)
|
audioBytes, _ := io.ReadAll(resp.Body)
|
||||||
if len(audioBytes) != audioSize {
|
if len(audioBytes) != audioSize {
|
||||||
@@ -78,7 +78,7 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
|||||||
// Round-trip through msgpack
|
// Round-trip through msgpack
|
||||||
data, _ := msgpack.Marshal(&msg)
|
data, _ := msgpack.Marshal(&msg)
|
||||||
var decoded messages.TTSAudioChunk
|
var decoded messages.TTSAudioChunk
|
||||||
msgpack.Unmarshal(data, &decoded)
|
_ = msgpack.Unmarshal(data, &decoded)
|
||||||
|
|
||||||
if decoded.SessionID != "test-session" {
|
if decoded.SessionID != "test-session" {
|
||||||
t.Errorf("chunk %d: session = %v", chunkIdx, decoded.SessionID)
|
t.Errorf("chunk %d: session = %v", chunkIdx, decoded.SessionID)
|
||||||
@@ -96,15 +96,15 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
// Set up voice registry with temp dir
|
// Set up voice registry with temp dir
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
voiceDir := filepath.Join(dir, "custom-en")
|
voiceDir := filepath.Join(dir, "custom-en")
|
||||||
os.MkdirAll(voiceDir, 0o755)
|
_ = os.MkdirAll(voiceDir, 0o755)
|
||||||
info := map[string]string{
|
info := map[string]string{
|
||||||
"name": "custom-en", "language": "en",
|
"name": "custom-en", "language": "en",
|
||||||
"type": "coqui-tts", "created_at": "2024-06-01",
|
"type": "coqui-tts", "created_at": "2024-06-01",
|
||||||
}
|
}
|
||||||
infoData, _ := json.Marshal(info)
|
infoData, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake-model"), 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake-model"), 0o644)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "config.json"), []byte("{}"), 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "config.json"), []byte("{}"), 0o644)
|
||||||
|
|
||||||
registry := newVoiceRegistry(dir)
|
registry := newVoiceRegistry(dir)
|
||||||
count := registry.refresh()
|
count := registry.refresh()
|
||||||
@@ -115,7 +115,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
// XTTS mock that validates custom voice fields
|
// XTTS mock that validates custom voice fields
|
||||||
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload map[string]any
|
var payload map[string]any
|
||||||
json.NewDecoder(r.Body).Decode(&payload)
|
_ = json.NewDecoder(r.Body).Decode(&payload)
|
||||||
|
|
||||||
// When custom voice is used, model_path should be set
|
// When custom voice is used, model_path should be set
|
||||||
if payload["model_path"] == nil {
|
if payload["model_path"] == nil {
|
||||||
@@ -124,7 +124,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
if payload["config_path"] == nil {
|
if payload["config_path"] == nil {
|
||||||
t.Error("expected config_path for voice with config")
|
t.Error("expected config_path for voice with config")
|
||||||
}
|
}
|
||||||
w.Write(make([]byte, 4000))
|
_, _ = w.Write(make([]byte, 4000))
|
||||||
}))
|
}))
|
||||||
defer xttsSrv.Close()
|
defer xttsSrv.Close()
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("status = %d, want 200", resp.StatusCode)
|
t.Errorf("status = %d, want 200", resp.StatusCode)
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
func TestSynthesisE2E_XTTSError(t *testing.T) {
|
func TestSynthesisE2E_XTTSError(t *testing.T) {
|
||||||
failSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
failSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(503)
|
w.WriteHeader(503)
|
||||||
w.Write([]byte("model not loaded"))
|
_, _ = w.Write([]byte("model not loaded"))
|
||||||
}))
|
}))
|
||||||
defer failSrv.Close()
|
defer failSrv.Close()
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ func TestSynthesisE2E_XTTSError(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 503 {
|
if resp.StatusCode != 503 {
|
||||||
t.Errorf("status = %d, want 503", resp.StatusCode)
|
t.Errorf("status = %d, want 503", resp.StatusCode)
|
||||||
}
|
}
|
||||||
@@ -182,11 +182,11 @@ func TestVoiceRegistryMultiple(t *testing.T) {
|
|||||||
// Create 3 voices
|
// Create 3 voices
|
||||||
for _, name := range []string{"alice", "bob", "charlie"} {
|
for _, name := range []string{"alice", "bob", "charlie"} {
|
||||||
vDir := filepath.Join(dir, name)
|
vDir := filepath.Join(dir, name)
|
||||||
os.MkdirAll(vDir, 0o755)
|
_ = os.MkdirAll(vDir, 0o755)
|
||||||
info := map[string]string{"name": name, "language": "en"}
|
info := map[string]string{"name": name, "language": "en"}
|
||||||
data, _ := json.Marshal(info)
|
data, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
||||||
os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
registry := newVoiceRegistry(dir)
|
registry := newVoiceRegistry(dir)
|
||||||
@@ -216,7 +216,7 @@ func TestVoiceRegistryMultiple(t *testing.T) {
|
|||||||
|
|
||||||
func BenchmarkSynthesisRoundtrip(b *testing.B) {
|
func BenchmarkSynthesisRoundtrip(b *testing.B) {
|
||||||
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(make([]byte, 16000))
|
_, _ = w.Write(make([]byte, 16000))
|
||||||
}))
|
}))
|
||||||
defer xttsSrv.Close()
|
defer xttsSrv.Close()
|
||||||
|
|
||||||
@@ -227,8 +227,8 @@ func BenchmarkSynthesisRoundtrip(b *testing.B) {
|
|||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
resp, _ := client.Post(xttsSrv.URL+"/v1/audio/speech", "application/json",
|
resp, _ := client.Post(xttsSrv.URL+"/v1/audio/speech", "application/json",
|
||||||
bytes.NewReader(body))
|
bytes.NewReader(body))
|
||||||
io.ReadAll(resp.Body)
|
_, _ = io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,11 +237,11 @@ func BenchmarkVoiceRegistryRefresh(b *testing.B) {
|
|||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
name := "voice-" + strconv.Itoa(i)
|
name := "voice-" + strconv.Itoa(i)
|
||||||
vDir := filepath.Join(dir, name)
|
vDir := filepath.Join(dir, name)
|
||||||
os.MkdirAll(vDir, 0o755)
|
_ = os.MkdirAll(vDir, 0o755)
|
||||||
info := map[string]string{"name": name}
|
info := map[string]string{"name": name}
|
||||||
data, _ := json.Marshal(info)
|
data, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
||||||
os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
registry := newVoiceRegistry(dir)
|
registry := newVoiceRegistry(dir)
|
||||||
@@ -272,7 +272,7 @@ func BenchmarkAudioChunking(b *testing.B) {
|
|||||||
Audio: chunk,
|
Audio: chunk,
|
||||||
SampleRate: 24000,
|
SampleRate: 24000,
|
||||||
}
|
}
|
||||||
msgpack.Marshal(msg)
|
_, _ = msgpack.Marshal(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -262,7 +262,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("xtts request: %w", err)
|
return nil, fmt.Errorf("xtts request: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
respBody, _ := io.ReadAll(resp.Body)
|
respBody, _ := io.ReadAll(resp.Body)
|
||||||
@@ -370,7 +370,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
packed, _ := msgpack.Marshal(resp)
|
packed, _ := msgpack.Marshal(resp)
|
||||||
if msg.Reply != "" {
|
if msg.Reply != "" {
|
||||||
msg.Respond(packed)
|
_ = msg.Respond(packed)
|
||||||
}
|
}
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
slog.Error("subscribe voices list failed", "error", err)
|
slog.Error("subscribe voices list failed", "error", err)
|
||||||
@@ -386,7 +386,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
packed, _ := msgpack.Marshal(resp)
|
packed, _ := msgpack.Marshal(resp)
|
||||||
if msg.Reply != "" {
|
if msg.Reply != "" {
|
||||||
msg.Respond(packed)
|
_ = msg.Respond(packed)
|
||||||
}
|
}
|
||||||
slog.Info("voice registry refreshed on demand", "count", count)
|
slog.Info("voice registry refreshed on demand", "count", count)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|||||||
16
main_test.go
16
main_test.go
@@ -19,11 +19,11 @@ func TestVoiceRegistryRefresh(t *testing.T) {
|
|||||||
|
|
||||||
// Create a voice directory
|
// Create a voice directory
|
||||||
voiceDir := filepath.Join(dir, "test-voice")
|
voiceDir := filepath.Join(dir, "test-voice")
|
||||||
os.MkdirAll(voiceDir, 0o755)
|
_ = os.MkdirAll(voiceDir, 0o755)
|
||||||
info := map[string]string{"name": "test-voice", "language": "en", "type": "coqui-tts", "created_at": "2024-01-01"}
|
info := map[string]string{"name": "test-voice", "language": "en", "type": "coqui-tts", "created_at": "2024-01-01"}
|
||||||
infoData, _ := json.Marshal(info)
|
infoData, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake"), 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake"), 0o644)
|
||||||
|
|
||||||
vr := newVoiceRegistry(dir)
|
vr := newVoiceRegistry(dir)
|
||||||
count := vr.refresh()
|
count := vr.refresh()
|
||||||
@@ -59,10 +59,10 @@ func TestVoiceRegistryMissing(t *testing.T) {
|
|||||||
func TestVoiceRegistryNoModel(t *testing.T) {
|
func TestVoiceRegistryNoModel(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
voiceDir := filepath.Join(dir, "bad-voice")
|
voiceDir := filepath.Join(dir, "bad-voice")
|
||||||
os.MkdirAll(voiceDir, 0o755)
|
_ = os.MkdirAll(voiceDir, 0o755)
|
||||||
info := map[string]string{"name": "bad-voice"}
|
info := map[string]string{"name": "bad-voice"}
|
||||||
infoData, _ := json.Marshal(info)
|
infoData, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
||||||
// No model.pth
|
// No model.pth
|
||||||
|
|
||||||
vr := newVoiceRegistry(dir)
|
vr := newVoiceRegistry(dir)
|
||||||
@@ -82,12 +82,12 @@ func TestSynthesizeHTTP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var payload map[string]any
|
var payload map[string]any
|
||||||
json.NewDecoder(r.Body).Decode(&payload)
|
_ = json.NewDecoder(r.Body).Decode(&payload)
|
||||||
if payload["text"] != "hello" {
|
if payload["text"] != "hello" {
|
||||||
t.Errorf("unexpected text: %v", payload["text"])
|
t.Errorf("unexpected text: %v", payload["text"])
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte{0x01, 0x02, 0x03, 0x04})
|
_, _ = w.Write([]byte{0x01, 0x02, 0x03, 0x04})
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ func TestSynthesizeHTTP(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("status = %d, want 200", resp.StatusCode)
|
t.Errorf("status = %d, want 200", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user