All checks were successful
Deploy to K8s / deploy (push) Successful in 11s
- io/attendance: CSV-over-public-URL client + Fake for adult/junior tabs - io/drive: Drive v3 modifiedTime client + Fake - io/sheets: Sheets v4 client (GetValues/AppendValues/BatchUpdateValues/ WriteHeader/SortByDateColumn) + Fake with call-capture - io/cache: Drive-modifiedTime-gated FileCache; two TTL knobs; atomic writes; generic Get[T]; Python-compatible JSON format; Flush() - io/fio: Client interface backed by Fio REST API (apiClient) and HTML scraper (transparentClient); Fake; testdata fixtures - membership/sources: NewSources wires attendance CSV + Sheets + cache into LoadAdults/LoadJuniors/LoadTransactions/LoadExceptions; Czech month parsing + merged-month maps - banksync: SyncToSheets (SHA-256 dedup, optional sort) and InferPayments ([?] review prefix, dry-run) — tested with fakes - cmd/fuj: sync and infer subcommands wired; fees and reconcile use real NewSources; go.mod gains google.golang.org/api + x/net - gofumpt extra-rules applied across all packages; lint clean Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
94 lines
2.0 KiB
Go
94 lines
2.0 KiB
Go
package attendance
|
|
|
|
import (
|
|
"context"
|
|
"encoding/csv"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestClientFetchAdults(t *testing.T) {
|
|
data, err := os.ReadFile("testdata/adults_minimal.csv")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
_, _ = w.Write(data)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
// Point the client at our test server by re-implementing fetch against its URL.
|
|
rows, err := fetchURL(context.Background(), srv.Client(), srv.URL)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(rows) < 2 {
|
|
t.Fatalf("want ≥2 rows, got %d", len(rows))
|
|
}
|
|
if rows[0][0] != "Jméno" {
|
|
t.Errorf("unexpected header: %q", rows[0][0])
|
|
}
|
|
}
|
|
|
|
func TestFake(t *testing.T) {
|
|
adultRows := parseCSV(t, "testdata/adults_minimal.csv")
|
|
juniorRows := parseCSV(t, "testdata/juniors_minimal.csv")
|
|
|
|
f := &Fake{Adults: adultRows, Juniors: juniorRows}
|
|
|
|
got, err := f.FetchAdults(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got[0][0] != "Jméno" {
|
|
t.Errorf("adults header: %q", got[0][0])
|
|
}
|
|
|
|
got, err = f.FetchJuniors(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got[1][0] != "Junior One" {
|
|
t.Errorf("juniors first member: %q", got[1][0])
|
|
}
|
|
}
|
|
|
|
func parseCSV(t *testing.T, path string) [][]string {
|
|
t.Helper()
|
|
b, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := csv.NewReader(strings.NewReader(string(b)))
|
|
r.FieldsPerRecord = -1
|
|
rows, err := r.ReadAll()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return rows
|
|
}
|
|
|
|
// fetchURL is a test helper that exercises the shared fetch logic against an arbitrary URL.
|
|
func fetchURL(ctx context.Context, hc *http.Client, url string) ([][]string, error) {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, err := hc.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
b, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
r := csv.NewReader(strings.NewReader(string(b)))
|
|
r.FieldsPerRecord = -1
|
|
return r.ReadAll()
|
|
}
|