1
package main
1
package main
2
2
3
import "encoding/json"
3
import "encoding/json"
4
import "testing"
4
import "testing"
5
5
6
import "oscarkilo.com/klex-git/api"
6
import "oscarkilo.com/klex-git/api"
7
7
8
func CheckEq(t *testing.T, golden, actual []Case) {
8
func CheckEq(t *testing.T, golden, actual []Case) {
9
t.Helper()
9
t.Helper()
10
g, err := json.MarshalIndent(golden, "", " ")
10
g, err := json.MarshalIndent(golden, "", " ")
11
if err != nil {
11
if err != nil {
12
t.Fatalf("json.MarshalIndent(golden) failed: %+v", err)
12
t.Fatalf("json.MarshalIndent(golden) failed: %+v", err)
13
}
13
}
14
a, err := json.MarshalIndent(actual, "", " ")
14
a, err := json.MarshalIndent(actual, "", " ")
15
if err != nil {
15
if err != nil {
16
t.Fatalf("json.MarshalIndent(actual) failed: %+v", err)
16
t.Fatalf("json.MarshalIndent(actual) failed: %+v", err)
17
}
17
}
18
if string(g) != string(a) {
18
if string(g) != string(a) {
19
t.Errorf("mismatch:\ngolden:\n%s\nactual:\n%s\n", g, a)
19
t.Errorf("mismatch:\ngolden:\n%s\nactual:\n%s\n", g, a)
20
}
20
}
21
}
21
}
22
22
23
func TestScanForCases(t *testing.T) {
23
func TestScanForCases(t *testing.T) {
24
// Get the path to the example dir next to this main_test.go file.
24
// Get the path to the example dir next to this main_test.go file.
25
*dir = "./example"
25
*dir = "./example"
26
golden := []Case{
26
golden := []Case{
27
Case{
27
Case{
28
Name: "2025-10-10",
28
Name: "2025-10-10",
29
Before: []string{"txt"},
29
Before: []string{"txt"},
30
After: "out",
30
After: "out",
31
},
31
},
32
Case{
32
Case{
33
Name: "2025-10-20",
33
Name: "2025-10-20",
34
Before: []string{"jpg"},
34
Before: []string{"jpg"},
35
},
35
},
36
Case{
36
Case{
37
Name: "2025-11-11",
37
Name: "2025-11-11",
38
Before: []string{"txt"},
38
Before: []string{"txt"},
39
},
39
},
40
Case{
41
Name: "2025-11-19",
42
Before: []string{"webp"},
43
},
40
}
44
}
41
CheckEq(t, golden, scanForCases())
45
CheckEq(t, golden, scanForCases())
42
}
46
}
43
47
44
func TestCopyRequest(t *testing.T) {
48
func TestCopyRequest(t *testing.T) {
45
a := &api.MessagesRequest{Model: "foo"}
49
a := &api.MessagesRequest{Model: "foo"}
46
b := copyRequest(*a)
50
b := copyRequest(*a)
47
a.Model = "bar"
51
a.Model = "bar"
48
if b.Model != "foo" {
52
if b.Model != "foo" {
49
t.Errorf("%s %s", a.Model, b.Model)
53
t.Errorf("%s %s", a.Model, b.Model)
50
}
54
}
51
}
55
}