-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
42 lines (36 loc) · 1.09 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestWriteDate(t *testing.T) {
// Backup original environment variables
originalTZ := os.Getenv("STAMPY_TZ")
originalFormat := os.Getenv("STAMPY_FORMAT")
originalNTP := os.Getenv("STAMPY_NTP")
defer func() {
os.Setenv("STAMPY_TZ", originalTZ)
os.Setenv("STAMPY_FORMAT", originalFormat)
os.Setenv("STAMPY_NTP", originalNTP)
}()
t.Run("Default behavior", func(t *testing.T) {
writeDate("", "", "", false)
// Add assertions based on expected output
})
t.Run("With environment variables", func(t *testing.T) {
os.Setenv("STAMPY_TZ", "America/New_York")
os.Setenv("STAMPY_FORMAT", "2006-01-02")
os.Setenv("STAMPY_NTP", "pool.ntp.org")
writeDate("", "", "", false)
// Add assertions based on expected output
})
t.Run("Diary format", func(t *testing.T) {
writeDate("", "", "", true)
// Add assertions based on expected output
})
t.Run("Error loading location", func(t *testing.T) {
os.Setenv("STAMPY_TZ", "Invalid/Timezone")
assert.Panics(t, func() { writeDate("", "", "", false) })
})
}