test(ci): fix windows tracking and capture flakes
This commit is contained in:
parent
c18c58c8da
commit
a96ad42e02
@ -3,6 +3,8 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -320,8 +322,8 @@ func TestDocsWriteUpdate_FileInputErrors(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("expected error for non-existent file, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "no such file") {
|
||||
t.Fatalf("expected 'no such file' error, got: %v", err)
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
t.Fatalf("expected fs.ErrNotExist, got: %v", err)
|
||||
}
|
||||
|
||||
// Test with empty file
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@ -80,13 +81,20 @@ func captureStdout(t *testing.T, fn func()) string {
|
||||
}
|
||||
os.Stdout = w
|
||||
|
||||
var buf bytes.Buffer
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
_, _ = io.Copy(&buf, r)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
fn()
|
||||
|
||||
_ = w.Close()
|
||||
os.Stdout = orig
|
||||
b, _ := io.ReadAll(r)
|
||||
<-done
|
||||
_ = r.Close()
|
||||
return string(b)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func captureStderr(t *testing.T, fn func()) string {
|
||||
@ -99,13 +107,20 @@ func captureStderr(t *testing.T, fn func()) string {
|
||||
}
|
||||
os.Stderr = w
|
||||
|
||||
var buf bytes.Buffer
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
_, _ = io.Copy(&buf, r)
|
||||
close(done)
|
||||
}()
|
||||
|
||||
fn()
|
||||
|
||||
_ = w.Close()
|
||||
os.Stderr = orig
|
||||
b, _ := io.ReadAll(r)
|
||||
<-done
|
||||
_ = r.Close()
|
||||
return string(b)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func withStdin(t *testing.T, input string, fn func()) {
|
||||
|
||||
@ -45,6 +45,10 @@ func ConfigPath() (string, error) {
|
||||
}
|
||||
|
||||
func legacyConfigPath() (string, error) {
|
||||
if xdg := strings.TrimSpace(os.Getenv("XDG_CONFIG_HOME")); xdg != "" {
|
||||
return filepath.Join(xdg, "gog", "tracking.json"), nil
|
||||
}
|
||||
|
||||
configDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("user config dir: %w", err)
|
||||
|
||||
@ -109,6 +109,19 @@ func TestLoadConfigLegacyFallback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyConfigPathUsesXDGConfigHome(t *testing.T) {
|
||||
setupTrackingConfigEnv(t)
|
||||
|
||||
path, err := legacyConfigPath()
|
||||
if err != nil {
|
||||
t.Fatalf("legacyConfigPath: %v", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(path, filepath.Join("xdg", "gog", "tracking.json")) {
|
||||
t.Fatalf("expected XDG-based legacy path, got %q", path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveConfigMissingAccount(t *testing.T) {
|
||||
setupTrackingConfigEnv(t)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user