From 15d817c5d19900b719f9d8a1ec2e2660e83231ae Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Tue, 13 Feb 2024 11:28:24 -0800 Subject: [PATCH] lets-go:14.1 failing unit tests --- snippetbox/cmd/web/templates_test.go | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 snippetbox/cmd/web/templates_test.go diff --git a/snippetbox/cmd/web/templates_test.go b/snippetbox/cmd/web/templates_test.go new file mode 100644 index 0000000..d65a3df --- /dev/null +++ b/snippetbox/cmd/web/templates_test.go @@ -0,0 +1,42 @@ +package main + +import ( + "testing" + "time" +) + +func TestHumanDate(t *testing.T) { + tests := []struct { + name string + tm time.Time + want string + }{ + { + name: "UTC", + tm: time.Date(2023, 3, 17, 10, 15, 0, 0, time.UTC), + want: "17 Mar 2023 at 10:15", + }, + { + name: "Empty", + tm: time.Time{}, + want: "", + }, + { + name: "CET", + tm: time.Date(2023, 3, 17, 10, 15, 0, 0, time.FixedZone("CET", 1*60*60)), + want: "17 Mar 2023 at 09:15", + }, + + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + hd := humanDate(tt.tm) + + if hd != tt.want { + t.Errorf("got %q; want %q", hd, tt.want) + } + }) + + } +}