summaryrefslogtreecommitdiff
path: root/internal/discovery/discovery_test.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-06-07 00:06:45 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-06-25 12:41:13 +0000
commit0de98aeaa92080519ff0e194fc9246ddd79aca6d (patch)
tree2f2b1842e30a8aef6d42c20f6d32de5c85f38f02 /internal/discovery/discovery_test.go
parente12a9820895b48de6d1b8408364fec45958bc6c5 (diff)
Discovery: Return a fresh boolean
Diffstat (limited to 'internal/discovery/discovery_test.go')
-rw-r--r--internal/discovery/discovery_test.go29
1 files changed, 24 insertions, 5 deletions
diff --git a/internal/discovery/discovery_test.go b/internal/discovery/discovery_test.go
index 03ea109..42191be 100644
--- a/internal/discovery/discovery_test.go
+++ b/internal/discovery/discovery_test.go
@@ -23,7 +23,10 @@ func TestServers(t *testing.T) {
}
d := &Discovery{httpClient: c}
// get servers
- s1, err := d.Servers(context.Background())
+ s1, fresh, err := d.Servers(context.Background())
+ if !fresh {
+ t.Fatalf("Did not obtain the server list fresh")
+ }
if err != nil {
t.Fatalf("Failed getting servers: %v", err)
}
@@ -31,8 +34,11 @@ func TestServers(t *testing.T) {
// Shutdown the server
s.Close()
// Test if we get the same cached copy
- s2, err := d.Servers(context.Background())
+ s2, fresh, err := d.Servers(context.Background())
// We should not get an error as the timestamp is not expired
+ if fresh {
+ t.Fatalf("The server list was obtained fresh")
+ }
if err != nil {
t.Fatalf("Got a servers error after shutting down server: %v", err)
}
@@ -41,9 +47,13 @@ func TestServers(t *testing.T) {
}
// Force expired, 1 hour in the past
+ // we should return the previous with an error
d.ServerList.Timestamp = time.Now().Add(-1 * time.Hour)
- s3, err := d.Servers(context.Background())
+ s3, fresh, err := d.Servers(context.Background())
+ if fresh {
+ t.Fatalf("Server list was gotten fresh")
+ }
// Now we expect an error with the cached copy
if err == nil {
t.Fatalf("Got a servers nil error after shutting down file server and expired")
@@ -65,16 +75,25 @@ func TestOrganizations(t *testing.T) {
}
d := &Discovery{httpClient: c}
// get servers
- s1, err := d.Organizations(context.Background())
+ s1, fresh, err := d.Organizations(context.Background())
+ if !fresh {
+ t.Fatalf("The organization list was not obtained fresh")
+ }
if err != nil {
t.Fatalf("Failed getting organizations: %v", err)
}
+ if !fresh {
+ t.Fatalf("Did not get a fresh organization list")
+ }
// Shutdown the server
s.Close()
// Test if we get the same cached copy
// We should not get an error as the timestamp is not zero
- s2, err := d.Organizations(context.Background())
+ s2, fresh, err := d.Organizations(context.Background())
+ if fresh {
+ t.Fatalf("The organization list is freshly obtained")
+ }
if err != nil {
t.Fatalf("Got an organizations error after shutting down file server: %v", err)
}