Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12142656
updates_test.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
updates_test.go
View Options
package
writefreely
import
(
"regexp"
"testing"
"time"
)
func
TestUpdatesRoundTrip
(
t
*
testing
.
T
)
{
cache
:=
newUpdatesCache
(
defaultUpdatesCacheTime
)
t
.
Run
(
"New Updates Cache"
,
func
(
t
*
testing
.
T
)
{
if
cache
==
nil
{
t
.
Fatal
(
"Returned nil cache"
)
}
if
cache
.
frequency
!=
defaultUpdatesCacheTime
{
t
.
Fatalf
(
"Got cache expiry frequency: %s but expected: %s"
,
cache
.
frequency
,
defaultUpdatesCacheTime
)
}
if
cache
.
currentVersion
!=
"v"
+
softwareVer
{
t
.
Fatalf
(
"Got current version: %s but expected: %s"
,
cache
.
currentVersion
,
"v"
+
softwareVer
)
}
})
t
.
Run
(
"Release URL"
,
func
(
t
*
testing
.
T
)
{
url
:=
cache
.
ReleaseNotesURL
()
reg
,
err
:=
regexp
.
Compile
(
`^https:\/\/blog.writefreely.org\/version(-\d+){1,}$`
)
if
err
!=
nil
{
t
.
Fatalf
(
"Test Case Error: Failed to compile regex: %v"
,
err
)
}
match
:=
reg
.
MatchString
(
url
)
if
!
match
{
t
.
Fatalf
(
"Malformed Release URL: %s"
,
url
)
}
})
t
.
Run
(
"Check Now"
,
func
(
t
*
testing
.
T
)
{
// ensure time between init and next check
time
.
Sleep
(
1
*
time
.
Second
)
prevLastCheck
:=
cache
.
lastCheck
// force to known older version for latest and current
prevLatestVer
:=
"v0.8.1"
cache
.
latestVersion
=
prevLatestVer
cache
.
currentVersion
=
"v0.8.0"
err
:=
cache
.
CheckNow
()
if
err
!=
nil
{
t
.
Fatalf
(
"Error should be nil, got: %v"
,
err
)
}
if
prevLastCheck
==
cache
.
lastCheck
{
t
.
Fatal
(
"Expected lastCheck to update"
)
}
if
cache
.
lastCheck
.
Before
(
prevLastCheck
)
{
t
.
Fatal
(
"Last check should be newer than previous"
)
}
if
prevLatestVer
==
cache
.
latestVersion
{
t
.
Fatal
(
"expected latestVersion to update"
)
}
})
t
.
Run
(
"Are Available"
,
func
(
t
*
testing
.
T
)
{
if
!
cache
.
AreAvailable
()
{
t
.
Fatalf
(
"Cache reports not updates but Current is %s and Latest is %s"
,
cache
.
currentVersion
,
cache
.
latestVersion
)
}
})
t
.
Run
(
"Latest Version"
,
func
(
t
*
testing
.
T
)
{
gotLatest
:=
cache
.
LatestVersion
()
if
gotLatest
!=
cache
.
latestVersion
{
t
.
Fatalf
(
"Malformed latest version. Expected: %s but got: %s"
,
cache
.
latestVersion
,
gotLatest
)
}
})
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 9, 11:38 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3390061
Attached To
rWF WriteFreely
Event Timeline
Log In to Comment