forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_test.go
55 lines (48 loc) · 1.16 KB
/
image_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
package models
import (
"testing"
"time"
"github.com/benbjohnson/clock"
"github.com/stretchr/testify/assert"
)
func TestImage_ExtendDuration(t *testing.T) {
var i Image
d := time.Now().Add(time.Minute)
i.ExpiresAt = d
// extend the duration for 1 minute
i.ExtendDuration(time.Minute)
assert.Equal(t, d.Add(time.Minute), i.ExpiresAt)
// can shorten the duration too
i.ExtendDuration(-time.Minute)
assert.Equal(t, d, i.ExpiresAt)
}
func TestImage_HasExpired(t *testing.T) {
oldTimeNow := timeNow
timeNow = clock.NewMock().Now
t.Cleanup(func() {
timeNow = oldTimeNow
})
var i Image
i.ExpiresAt = timeNow().Add(time.Minute)
assert.False(t, i.HasExpired())
i.ExpiresAt = timeNow()
assert.False(t, i.HasExpired())
i.ExpiresAt = timeNow().Add(-time.Minute)
assert.True(t, i.HasExpired())
}
func TestImage_HasPath(t *testing.T) {
var i Image
assert.False(t, i.HasPath())
i.Path = "/"
assert.True(t, i.HasPath())
i.Path = "/tmp/image.png"
assert.True(t, i.HasPath())
}
func TestImage_HasURL(t *testing.T) {
var i Image
assert.False(t, i.HasURL())
i.URL = "/"
assert.True(t, i.HasURL())
i.URL = "https://example.com/image.png"
assert.True(t, i.HasURL())
}