diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-11 20:25:30 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-11 20:25:30 +0300 |
commit | a5548d71b72b050df4d708953120af5f16dde39b (patch) | |
tree | b4afde6c7168dfa127fbf8402acd79c6bc6a8ff1 /domains_test.go | |
parent | 9bc5a5ff0b4bbbf8ef2fab821bc974909d276982 (diff) |
Added more behavior tests
Diffstat (limited to 'domains_test.go')
-rw-r--r-- | domains_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/domains_test.go b/domains_test.go index 5c16aa14..ae849f46 100644 --- a/domains_test.go +++ b/domains_test.go @@ -4,8 +4,14 @@ import ( "testing" "github.com/stretchr/testify/require" "github.com/stretchr/testify/assert" + "time" + "io/ioutil" + "crypto/rand" + "os" ) +const updateFile = "shared/pages/.update" + func TestReadProjects(t *testing.T) { *pagesDomain = "test.io" @@ -33,3 +39,33 @@ func TestReadProjects(t *testing.T) { assert.Contains(t, expectedDomains, actual) } } + +func writeRandomTimestamp() { + b := make([]byte, 10) + rand.Read(b) + ioutil.WriteFile(updateFile, b, 0600) +} + +func TestWatchDomains(t *testing.T) { + update := make(chan domains) + go watchDomains(func(domains domains) { + update <- domains + }, time.Microsecond) + + defer os.Remove(updateFile) + + domains := <-update + assert.NotNil(t, domains, "if the domains are fetched on start") + + writeRandomTimestamp() + domains = <-update + assert.NotNil(t, domains, "if the domains are updated after the creation") + + writeRandomTimestamp() + domains = <-update + assert.NotNil(t, domains, "if the domains are updated after the timestamp change") + + os.Remove(updateFile) + domains = <-update + assert.NotNil(t, domains, "if the domains are updated after the timestamp removal") +} |