mirror of
https://codeberg.org/readeck/readeck.git
synced 2025-12-22 05:07:08 +00:00
Load embedded tzdata and force TZ on some time related tests.
time/tzdata embeds a local copy of tzdata if the system has none. use testing.T.Setenv to force a specific timezone on some tests.
This commit is contained in:
@@ -35,6 +35,8 @@ type adapterTest struct {
|
||||
}
|
||||
|
||||
func TestFileAdapters(t *testing.T) {
|
||||
t.Setenv("TZ", "Europe/Paris")
|
||||
|
||||
tests := []adapterTest{
|
||||
{
|
||||
importer.LoadAdapter("text"),
|
||||
@@ -412,6 +414,8 @@ func TestFileAdapters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWallabagImporter(t *testing.T) {
|
||||
t.Setenv("TZ", "Europe/Paris")
|
||||
|
||||
adapter := importer.LoadAdapter("wallabag")
|
||||
f := importer.NewImportForm(context.Background(), adapter)
|
||||
_ = f.Get("url").UnmarshalValues([]string{"https://wallabag/"})
|
||||
@@ -520,6 +524,8 @@ func TestWallabagImporter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOmnivoreImporter(t *testing.T) {
|
||||
t.Setenv("TZ", "Europe/Paris")
|
||||
|
||||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
|
||||
1
main.go
1
main.go
@@ -8,6 +8,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
_ "time/tzdata" // load embedded tzdata
|
||||
|
||||
"codeberg.org/readeck/readeck/internal/app"
|
||||
)
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func TestStrftime(t *testing.T) {
|
||||
t.Setenv("TZ", "Europe/Amsterdam")
|
||||
|
||||
tests := []struct {
|
||||
date string
|
||||
format string
|
||||
@@ -62,9 +64,7 @@ func TestStrftime(t *testing.T) {
|
||||
|
||||
for i, test := range tests {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
location, err := time.LoadLocation("CET")
|
||||
require.NoError(t, err)
|
||||
date, err := time.ParseInLocation(time.RFC3339, test.date, location)
|
||||
date, err := time.Parse(time.RFC3339, test.date)
|
||||
require.NoError(t, err)
|
||||
t.Log(date, test.format, strftime.Strftime(test.format, date))
|
||||
|
||||
@@ -74,6 +74,8 @@ func TestStrftime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTranslator(t *testing.T) {
|
||||
t.Setenv("TZ", "Europe/Amsterdam")
|
||||
|
||||
tests := []struct {
|
||||
date string
|
||||
format string
|
||||
@@ -96,9 +98,7 @@ func TestTranslator(t *testing.T) {
|
||||
f := strftime.New(translation)
|
||||
for i, test := range tests {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
location, err := time.LoadLocation("CET")
|
||||
require.NoError(t, err)
|
||||
date, err := time.ParseInLocation(time.RFC3339, test.date, location)
|
||||
date, err := time.Parse(time.RFC3339, test.date)
|
||||
require.NoError(t, err)
|
||||
t.Log(date, test.format, f.Strftime(test.format, date))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user