forked from damongolding/immich-kiosk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmich_test.go
107 lines (88 loc) · 2.18 KB
/
immich_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package immich
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/charmbracelet/log"
"github.com/damongolding/immich-kiosk/config"
)
// TestGetRandomImage testing if no images are found. Should retry 10 times
func TestGetRandomImage(t *testing.T) {
log.SetLevel(log.DebugLevel)
// Start a local HTTP server
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
imgRes := make([]ImmichAsset, 5)
for i := range 5 {
imgRes[i] = ImmichAsset{
Type: "VIDEO",
}
}
out, _ := json.Marshal(imgRes)
// Send response to be tested
rw.Write(out)
}))
// Close the server when test finishes
defer server.Close()
c := config.New()
c.ImmichUrl = server.URL
c.ImmichApiKey = "123456"
i := NewImage(*c)
err := i.GetRandomImage("TESTING")
if err == nil {
t.Error("A image was found")
return
}
if err.Error() != "No images found" && i.Retries != 10 {
t.Error(err)
}
}
func TestArchiveLogic(t *testing.T) {
tests := []struct {
Type string
IsTrashed bool
IsArchived bool
ArchivedWantedByUser bool
WantSimulatedContinue bool
}{
{
Type: "IMAGE",
IsTrashed: false,
IsArchived: false,
ArchivedWantedByUser: false,
WantSimulatedContinue: false,
},
{
Type: "IMAGE",
IsTrashed: true,
IsArchived: false,
ArchivedWantedByUser: false,
WantSimulatedContinue: true,
},
{
Type: "IMAGE",
IsTrashed: false,
IsArchived: true,
ArchivedWantedByUser: false,
WantSimulatedContinue: true,
},
{
Type: "IMAGE",
IsTrashed: false,
IsArchived: true,
ArchivedWantedByUser: true,
WantSimulatedContinue: false,
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
simulatedContinueTriggered := false
if test.Type != "IMAGE" || test.IsTrashed || (test.IsArchived && !test.ArchivedWantedByUser) {
simulatedContinueTriggered = true
}
if simulatedContinueTriggered != test.WantSimulatedContinue {
t.Error()
}
})
}
}