Tariff: base cache validity on update interval instead of rate coverage (#32168)
This commit is contained in:
parent
60f313cbfb
commit
be81052667
4 changed files with 85 additions and 45 deletions
29
tariff/proxy_cache_test.go
Normal file
29
tariff/proxy_cache_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package tariff
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/server/db"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCacheInterval(t *testing.T) {
|
||||
require.NoError(t, db.NewInstance("sqlite", ":memory:"))
|
||||
|
||||
p := &cachingProxy{key: "test", interval: time.Hour}
|
||||
require.NoError(t, p.cachePut(api.TariffTypeSolar, api.Rates{
|
||||
{Start: time.Now(), End: time.Now().Add(time.Hour), Value: 1},
|
||||
}))
|
||||
|
||||
// within interval
|
||||
res, err := p.cacheGet()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, api.TariffTypeSolar, res.Type)
|
||||
|
||||
// interval elapsed
|
||||
p.cached.Updated = time.Now().Add(-2 * time.Hour)
|
||||
_, err = p.cacheGet()
|
||||
require.Error(t, err)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue