diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-10-17 10:43:58 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-17 12:53:24 -0700 |
commit | aab55cfbcdbcdea3610beb5f02d276d2e417cedb (patch) | |
tree | c1998925d0c96da7b11ce2c9121b8b263b5168ce /platform/darwin/test | |
parent | c66f92f4529b25d031f9c93687761647c48d8ae8 (diff) | |
download | qtlocation-mapboxgl-aab55cfbcdbcdea3610beb5f02d276d2e417cedb.tar.gz |
[darwin,test] Add "must-revalidate" support to putResourceWithURL
Testing must-revalidate: true required an expiration date in the future, which exposed a round-tripping problem from translating NSDate to time_point based on now().
Use epoch of 1970 instead (although technically it's not guaranteed to be the epoch for system_clock until C++20)
Diffstat (limited to 'platform/darwin/test')
-rw-r--r-- | platform/darwin/test/MGLOfflineStorageTests.mm | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/platform/darwin/test/MGLOfflineStorageTests.mm b/platform/darwin/test/MGLOfflineStorageTests.mm index cc396814d0..f01e6854b7 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.mm +++ b/platform/darwin/test/MGLOfflineStorageTests.mm @@ -400,7 +400,7 @@ MGLOfflineStorage *os = [MGLOfflineStorage sharedOfflineStorage]; std::string testData("test data"); - [os putResourceWithUrl:styleURL data:[NSData dataWithBytes:testData.c_str() length:testData.length()] modified:nil expires:nil etag:nil]; + [os putResourceWithUrl:styleURL data:[NSData dataWithBytes:testData.c_str() length:testData.length()] modified:nil expires:nil etag:nil mustRevalidate:NO]; auto fs = os.mbglFileSource; const mbgl::Resource resource { mbgl::Resource::Unknown, "https://api.mapbox.com/some/thing" }; @@ -412,6 +412,7 @@ XCTAssertFalse(res.modified, @"Request should not have a modification timestamp"); XCTAssertFalse(res.expires, @"Request should not have an expiration timestamp"); XCTAssertFalse(res.etag, @"Request should not have an entity tag"); + XCTAssertFalse(res.mustRevalidate, @"Request should not require revalidation"); XCTAssertEqual("test data", *res.data, @"Request did not return expected data"); CFRunLoopStop(CFRunLoopGetCurrent()); }); @@ -425,7 +426,8 @@ MGLOfflineStorage *os = [MGLOfflineStorage sharedOfflineStorage]; std::string testData("test data"); NSDate* now = [NSDate date]; - [os putResourceWithUrl:styleURL data:[NSData dataWithBytes:testData.c_str() length:testData.length()] modified:now expires:now etag:@"some etag"]; + NSDate* future = [now dateByAddingTimeInterval:600]; + [os putResourceWithUrl:styleURL data:[NSData dataWithBytes:testData.c_str() length:testData.length()] modified:now expires:future etag:@"some etag" mustRevalidate:YES]; auto fs = os.mbglFileSource; const mbgl::Resource resource { mbgl::Resource::Unknown, "https://api.mapbox.com/some/thing" }; @@ -437,9 +439,10 @@ XCTAssertTrue(res.modified, @"Request should have a modification timestamp"); XCTAssertEqual(MGLTimeIntervalFromDuration(res.modified->time_since_epoch()), floor(now.timeIntervalSince1970), @"Modification timestamp should roundtrip"); XCTAssertTrue(res.expires, @"Request should have an expiration timestamp"); - XCTAssertEqual(MGLTimeIntervalFromDuration(res.expires->time_since_epoch()), floor(now.timeIntervalSince1970), @"Expiration timestamp should roundtrip"); + XCTAssertEqual(MGLTimeIntervalFromDuration(res.expires->time_since_epoch()), floor(future.timeIntervalSince1970), @"Expiration timestamp should roundtrip"); XCTAssertTrue(res.etag, @"Request should have an entity tag"); XCTAssertEqual(*res.etag, "some etag", @"Entity tag should roundtrip"); + XCTAssertTrue(res.mustRevalidate, @"Request should require revalidation"); XCTAssertEqual("test data", *res.data, @"Request did not return expected data"); CFRunLoopStop(CFRunLoopGetCurrent()); }); |