Procházet zdrojové kódy

test(timezone): add test for `AvailableTimezones()`

Frédéric Guillot před 2 měsíci
rodič
revize
71c551ffe0

+ 4 - 3
internal/timezone/timezone.go

@@ -465,7 +465,7 @@ var (
 	}
 )
 
-// Convert converts provided date time to actual timezone.
+// Convert returns the provided time expressed in the given timezone.
 func Convert(tz string, t time.Time) time.Time {
 	userTimezone := getLocation(tz)
 
@@ -494,7 +494,7 @@ func Convert(tz string, t time.Time) time.Time {
 	return t
 }
 
-// Now returns the current time with the given timezone.
+// Now returns the current time in the given timezone.
 func Now(tz string) time.Time {
 	return time.Now().In(getLocation(tz))
 }
@@ -513,12 +513,13 @@ func getLocation(tz string) *time.Location {
 	return loc
 }
 
+// IsValid reports whether the timezone string is in the supported list.
 func IsValid(timezone string) bool {
 	_, found := slices.BinarySearch(timezones, timezone)
 	return found
 }
 
-// AvailableTimezones returns an iterator over supported timezones.
+// AvailableTimezones returns an iterator over supported timezone names.
 func AvailableTimezones() iter.Seq[string] {
 	return func(yield func(string) bool) {
 		for _, tz := range timezones {

+ 13 - 0
internal/timezone/timezone_test.go

@@ -4,6 +4,7 @@
 package timezone // import "miniflux.app/v2/internal/timezone"
 
 import (
+	"slices"
 	"testing"
 	"time"
 
@@ -114,3 +115,15 @@ func TestIsValid(t *testing.T) {
 		}
 	}
 }
+
+func TestAvailableTimezones(t *testing.T) {
+	var got []string
+
+	for tz := range AvailableTimezones() {
+		got = append(got, tz)
+	}
+
+	if !slices.Equal(got, timezones) {
+		t.Fatalf("available timezones differ from source slice: expected %d entries, got %d", len(timezones), len(got))
+	}
+}