code.oscarkilo.com/klex-git/exemplary/main_test.go

..
README.md
example/
main.go
main_test.go
package main

import "encoding/json"
import "testing"

import "oscarkilo.com/klex-git/api"

func CheckEq(t *testing.T, golden, actual []Case) {
  t.Helper()
  g, err := json.MarshalIndent(golden, "", "  ")
  if err != nil {
    t.Fatalf("json.MarshalIndent(golden) failed: %+v", err)
  }
  a, err := json.MarshalIndent(actual, "", "  ")
  if err != nil {
    t.Fatalf("json.MarshalIndent(actual) failed: %+v", err)
  }
  if string(g) != string(a) {
    t.Errorf("mismatch:\ngolden:\n%s\nactual:\n%s\n", g, a)
  }
}

func TestScanForCases(t *testing.T) {
  // Get the path to the example dir next to this main_test.go file.
  *dir = "./example"
  golden := []Case{
    Case{
      Name: "2025-10-10",
      Before: []string{"txt"},
      After: "out",
    },
    Case{
      Name: "2025-10-20",
      Before: []string{"jpg"},
    },
    Case{
      Name: "2025-11-11",
      Before: []string{"txt"},
    },
  }
  CheckEq(t, golden, scanForCases())
}

func TestCopyRequest(t *testing.T) {
  a := &api.MessagesRequest{Model: "foo"}
  b := copyRequest(*a)
  a.Model = "bar"
  if b.Model != "foo" {
    t.Errorf("%s %s", a.Model, b.Model)
  }
}