diff options
Diffstat (limited to 'internal/discovery/discovery_test.go')
| -rw-r--r-- | internal/discovery/discovery_test.go | 29 |
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) } |
