-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generation timestamp to metadata (#516)
* Add generation timestamp to metadata Co-authored-by: Daniel Beck <daniel-beck@users.noreply.github.com>
- Loading branch information
1 parent
4d0e446
commit ce77209
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.jenkins.update_center; | ||
|
||
import io.jenkins.update_center.json.WithSignature; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class TimestampTest { | ||
@Test | ||
public void checkTimestamp() throws Exception { | ||
WithSignature w = new WithSignature() { | ||
}; | ||
|
||
String timestamp = w.getGenerationTimestamp(); | ||
|
||
Assert.assertTrue("format as expected", timestamp.matches("^202[0-9][-][0-9]{2}[-][0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$")); | ||
|
||
Instant parsed = Instant.parse(timestamp); | ||
|
||
Assert.assertTrue("before now", parsed.isBefore(Instant.now())); | ||
Assert.assertTrue("very recent", parsed.isAfter(Instant.now().minus(1, ChronoUnit.SECONDS))); | ||
|
||
String timestamp2 = w.getGenerationTimestamp(); | ||
Assert.assertEquals("Doesn't change over time", timestamp, timestamp2); | ||
|
||
} | ||
} |