updated time
This commit is contained in:
1 parent
fc1673dcff
commit
8ade787421
3 files changed
+33
-7
No files matched your search
+12
-2
@@ -2,15 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHandleIndexRendersWatts(t *testing.T) {
|
||||
srv := &server{secret: "secret", store: &store{value: 123}}
|
||||
srv := &server{secret: "secret", store: &store{value: 123, updatedAt: time.Date(2026, 4, 20, 12, 34, 56, 0, time.UTC)}}
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
@@ -22,6 +23,12 @@ func TestHandleIndexRendersWatts(t *testing.T) {
|
||||
if !strings.Contains(rec.Body.String(), "123") {
|
||||
t.Fatalf("response did not contain watt value: %s", rec.Body.String())
|
||||
}
|
||||
if !strings.Contains(rec.Body.String(), "Last updated:") {
|
||||
t.Fatalf("response did not contain last updated label: %s", rec.Body.String())
|
||||
}
|
||||
if !strings.Contains(rec.Body.String(), "20.04.2026 12:34:56") {
|
||||
t.Fatalf("response did not contain german datetime: %s", rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleWriteRequiresSecret(t *testing.T) {
|
||||
@@ -52,6 +59,9 @@ func TestHandleWriteStoresValue(t *testing.T) {
|
||||
if got := srv.store.get(); got != 456 {
|
||||
t.Fatalf("stored watts = %d, want %d", got, 456)
|
||||
}
|
||||
if srv.store.updatedAt.IsZero() {
|
||||
t.Fatal("updatedAt was not set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user