The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/services/ngalert/models/image_test.go

49 lines
1.0 KiB

package models
import (
"testing"
"time"
"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) {
var i Image
i.ExpiresAt = time.Now().Add(time.Minute)
assert.False(t, i.HasExpired())
i.ExpiresAt = time.Now()
assert.True(t, i.HasExpired())
i.ExpiresAt = time.Now().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())
}