summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-06-27 19:43:27 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-06-27 20:09:00 +0000
commit979da77c1c91520793c6c307df8c5c3b6822b28f (patch)
tree4f01c6f1e8e3a0bfcaee25b63209f52c509b2156 /internal
parent4962d0e2d37e93af20c8afdae6f59d4656f272f3 (diff)
Discovery: Test for #55
Diffstat (limited to 'internal')
-rw-r--r--internal/discovery/discovery_test.go63
1 files changed, 61 insertions, 2 deletions
diff --git a/internal/discovery/discovery_test.go b/internal/discovery/discovery_test.go
index 42191be..1101bb2 100644
--- a/internal/discovery/discovery_test.go
+++ b/internal/discovery/discovery_test.go
@@ -23,7 +23,7 @@ func TestServers(t *testing.T) {
}
d := &Discovery{httpClient: c}
// get servers
- s1, fresh, err := d.Servers(context.Background())
+ _, fresh, err := d.Servers(context.Background())
if !fresh {
t.Fatalf("Did not obtain the server list fresh")
}
@@ -31,6 +31,36 @@ func TestServers(t *testing.T) {
t.Fatalf("Failed getting servers: %v", err)
}
+ // force expired
+ d.ServerList.Timestamp = time.Now().Add(-1 * time.Hour)
+
+ // override the last server with a keyword list
+ // and make sure a new fetch doesn't copy over the keyword list
+ // to the last entry
+ d.ServerList.List[len(d.ServerList.List)-1] = Server{
+ Server: discotypes.Server{
+ BaseURL: "https://example.org/",
+ DisplayName: map[string]string{
+ "en": "example",
+ },
+ Type: "institute_access",
+ },
+ KeywordList: map[string]string{
+ "en": "test bla",
+ },
+ SupportContact: []string{"mailto:test@example.org"},
+ }
+ s1, fresh, err := d.Servers(context.Background())
+ if !fresh {
+ t.Fatalf("Did not obtain the server list fresh after inserting a mock entry and faking expiry")
+ }
+ if err != nil {
+ t.Fatalf("Failed getting servers after inserting a mock entry: %v", err)
+ }
+ if kws := s1.List[len(s1.List)-1].KeywordList; kws != nil {
+ t.Fatalf("KeywordList is not nil when getting a fresh server list after inserting a mock entry: %v", kws)
+ }
+
// Shutdown the server
s.Close()
// Test if we get the same cached copy
@@ -75,7 +105,7 @@ func TestOrganizations(t *testing.T) {
}
d := &Discovery{httpClient: c}
// get servers
- s1, fresh, err := d.Organizations(context.Background())
+ _, fresh, err := d.Organizations(context.Background())
if !fresh {
t.Fatalf("The organization list was not obtained fresh")
}
@@ -86,6 +116,35 @@ func TestOrganizations(t *testing.T) {
t.Fatalf("Did not get a fresh organization list")
}
+ // force expired
+ d.OrganizationList.Timestamp = time.Now().Add(-4 * time.Hour)
+
+ // override the last organization with a keyword list
+ // and make sure a new fetch doesn't copy over the keyword list
+ // to the last entry
+ d.OrganizationList.List[len(d.OrganizationList.List)-1] = Organization{
+ Organization: discotypes.Organization{
+ DisplayName: map[string]string{
+ "en": "example",
+ },
+ OrgID: "example_orgid",
+ },
+ SecureInternetHome: "example.org",
+ KeywordList: map[string]string{
+ "en": "test bla",
+ },
+ }
+ s1, fresh, err := d.Organizations(context.Background())
+ if !fresh {
+ t.Fatalf("Did not obtain the organization list fresh after inserting a mock entry and faking expiry")
+ }
+ if err != nil {
+ t.Fatalf("Failed getting organizations after inserting a mock entry: %v", err)
+ }
+ if kws := s1.List[len(s1.List)-1].KeywordList; kws != nil {
+ t.Fatalf("KeywordList is not nil when getting a fresh organization list after inserting a mock entry: %v", kws)
+ }
+
// Shutdown the server
s.Close()
// Test if we get the same cached copy