shorten ucache to uc in misc test

shorten a few bits of html
This commit is contained in:
Azareal 2020-04-02 17:39:49 +10:00
parent 21d09db477
commit 581f86eeba
5 changed files with 49 additions and 49 deletions

View File

@ -49,17 +49,17 @@ func TestUserStore(t *testing.T) {
} }
var err error var err error
ucache := c.NewMemoryUserCache(c.Config.UserCacheCapacity) uc := c.NewMemoryUserCache(c.Config.UserCacheCapacity)
c.Users, err = c.NewDefaultUserStore(ucache) c.Users, err = c.NewDefaultUserStore(uc)
expectNilErr(t, err) expectNilErr(t, err)
ucache.Flush() uc.Flush()
userStoreTest(t, 2) userStoreTest(t, 2)
c.Users, err = c.NewDefaultUserStore(nil) c.Users, err = c.NewDefaultUserStore(nil)
expectNilErr(t, err) expectNilErr(t, err)
userStoreTest(t, 5) userStoreTest(t, 5)
} }
func userStoreTest(t *testing.T, newUserID int) { func userStoreTest(t *testing.T, newUserID int) {
ucache := c.Users.GetCache() uc := c.Users.GetCache()
// Go doesn't have short-circuiting, so this'll allow us to do one liner tests // Go doesn't have short-circuiting, so this'll allow us to do one liner tests
isCacheLengthZero := func(uc c.UserCache) bool { isCacheLengthZero := func(uc c.UserCache) bool {
if uc == nil { if uc == nil {
@ -73,15 +73,15 @@ func userStoreTest(t *testing.T, newUserID int) {
} }
return uc.Length() return uc.Length()
} }
expect(t, isCacheLengthZero(ucache), fmt.Sprintf("The initial ucache length should be zero, not %d", cacheLength(ucache))) expect(t, isCacheLengthZero(uc), fmt.Sprintf("The initial ucache length should be zero, not %d", cacheLength(uc)))
_, err := c.Users.Get(-1) _, err := c.Users.Get(-1)
recordMustNotExist(t, err, "UID #-1 shouldn't exist") recordMustNotExist(t, err, "UID #-1 shouldn't exist")
expect(t, isCacheLengthZero(ucache), fmt.Sprintf("We found %d items in the user cache and it's supposed to be empty", cacheLength(ucache))) expect(t, isCacheLengthZero(uc), fmt.Sprintf("We found %d items in the user cache and it's supposed to be empty", cacheLength(uc)))
_, err = c.Users.Get(0) _, err = c.Users.Get(0)
recordMustNotExist(t, err, "UID #0 shouldn't exist") recordMustNotExist(t, err, "UID #0 shouldn't exist")
expect(t, isCacheLengthZero(ucache), fmt.Sprintf("We found %d items in the user cache and it's supposed to be empty", cacheLength(ucache))) expect(t, isCacheLengthZero(uc), fmt.Sprintf("We found %d items in the user cache and it's supposed to be empty", cacheLength(uc)))
user, err := c.Users.Get(1) user, err := c.Users.Get(1)
recordMustExist(t, err, "Couldn't find UID #1") recordMustExist(t, err, "Couldn't find UID #1")
@ -110,34 +110,34 @@ func userStoreTest(t *testing.T, newUserID int) {
_, err = c.Users.Get(newUserID) _, err = c.Users.Get(newUserID)
recordMustNotExist(t, err, fmt.Sprintf("UID #%d shouldn't exist", newUserID)) recordMustNotExist(t, err, fmt.Sprintf("UID #%d shouldn't exist", newUserID))
if ucache != nil { if uc != nil {
expectIntToBeX(t, ucache.Length(), 1, "User cache length should be 1, not %d") expectIntToBeX(t, uc.Length(), 1, "User cache length should be 1, not %d")
_, err = ucache.Get(-1) _, err = uc.Get(-1)
recordMustNotExist(t, err, "UID #-1 shouldn't exist, even in the cache") recordMustNotExist(t, err, "UID #-1 shouldn't exist, even in the cache")
_, err = ucache.Get(0) _, err = uc.Get(0)
recordMustNotExist(t, err, "UID #0 shouldn't exist, even in the cache") recordMustNotExist(t, err, "UID #0 shouldn't exist, even in the cache")
user, err = ucache.Get(1) user, err = uc.Get(1)
recordMustExist(t, err, "Couldn't find UID #1 in the cache") recordMustExist(t, err, "Couldn't find UID #1 in the cache")
expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
expect(t, user.Name == "Admin", fmt.Sprintf("user.Name should be 'Admin', not '%s'", user.Name)) expect(t, user.Name == "Admin", fmt.Sprintf("user.Name should be 'Admin', not '%s'", user.Name))
_, err = ucache.Get(newUserID) _, err = uc.Get(newUserID)
recordMustNotExist(t, err, "UID #%d shouldn't exist, even in the cache", newUserID) recordMustNotExist(t, err, "UID #%d shouldn't exist, even in the cache", newUserID)
ucache.Flush() uc.Flush()
expectIntToBeX(t, ucache.Length(), 0, "User cache length should be 0, not %d") expectIntToBeX(t, uc.Length(), 0, "User cache length should be 0, not %d")
} }
// TODO: Lock onto the specific error type. Is this even possible without sacrificing the detailed information in the error message? // TODO: Lock onto the specific error type. Is this even possible without sacrificing the detailed information in the error message?
var userList map[int]*c.User var userList map[int]*c.User
userList, _ = c.Users.BulkGetMap([]int{-1}) userList, _ = c.Users.BulkGetMap([]int{-1})
expect(t, len(userList) == 0, fmt.Sprintf("The userList length should be 0, not %d", len(userList))) expect(t, len(userList) == 0, fmt.Sprintf("The userList length should be 0, not %d", len(userList)))
expect(t, isCacheLengthZero(ucache), fmt.Sprintf("User cache length should be 0, not %d", cacheLength(ucache))) expect(t, isCacheLengthZero(uc), fmt.Sprintf("User cache length should be 0, not %d", cacheLength(uc)))
userList, _ = c.Users.BulkGetMap([]int{0}) userList, _ = c.Users.BulkGetMap([]int{0})
expect(t, len(userList) == 0, fmt.Sprintf("The userList length should be 0, not %d", len(userList))) expect(t, len(userList) == 0, fmt.Sprintf("The userList length should be 0, not %d", len(userList)))
expect(t, isCacheLengthZero(ucache), fmt.Sprintf("User cache length should be 0, not %d", cacheLength(ucache))) expect(t, isCacheLengthZero(uc), fmt.Sprintf("User cache length should be 0, not %d", cacheLength(uc)))
userList, _ = c.Users.BulkGetMap([]int{1}) userList, _ = c.Users.BulkGetMap([]int{1})
expect(t, len(userList) == 1, fmt.Sprintf("Returned map should have one result (UID #1), not %d", len(userList))) expect(t, len(userList) == 1, fmt.Sprintf("Returned map should have one result (UID #1), not %d", len(userList)))
@ -150,13 +150,13 @@ func userStoreTest(t *testing.T, newUserID int) {
} }
expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
if ucache != nil { if uc != nil {
expectIntToBeX(t, ucache.Length(), 1, "User cache length should be 1, not %d") expectIntToBeX(t, uc.Length(), 1, "User cache length should be 1, not %d")
user, err = ucache.Get(1) user, err = uc.Get(1)
recordMustExist(t, err, "Couldn't find UID #1 in the cache") recordMustExist(t, err, "Couldn't find UID #1 in the cache")
expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
ucache.Flush() uc.Flush()
} }
expect(t, !c.Users.Exists(-1), "UID #-1 shouldn't exist") expect(t, !c.Users.Exists(-1), "UID #-1 shouldn't exist")
@ -164,7 +164,7 @@ func userStoreTest(t *testing.T, newUserID int) {
expect(t, c.Users.Exists(1), "UID #1 should exist") expect(t, c.Users.Exists(1), "UID #1 should exist")
expect(t, !c.Users.Exists(newUserID), fmt.Sprintf("UID #%d shouldn't exist", newUserID)) expect(t, !c.Users.Exists(newUserID), fmt.Sprintf("UID #%d shouldn't exist", newUserID))
expect(t, isCacheLengthZero(ucache), fmt.Sprintf("User cache length should be 0, not %d", cacheLength(ucache))) expect(t, isCacheLengthZero(uc), fmt.Sprintf("User cache length should be 0, not %d", cacheLength(uc)))
expectIntToBeX(t, c.Users.Count(), 1, "The number of users should be one, not %d") expectIntToBeX(t, c.Users.Count(), 1, "The number of users should be one, not %d")
awaitingActivation := 5 awaitingActivation := 5
@ -178,9 +178,9 @@ func userStoreTest(t *testing.T, newUserID int) {
recordMustExist(t, err, "Couldn't find UID #%d", newUserID) recordMustExist(t, err, "Couldn't find UID #%d", newUserID)
expectUser(user, newUserID, "Sam", 5, false, false, false, false) expectUser(user, newUserID, "Sam", 5, false, false, false, false)
if ucache != nil { if uc != nil {
expectIntToBeX(t, ucache.Length(), 1, "User cache length should be 1, not %d") expectIntToBeX(t, uc.Length(), 1, "User cache length should be 1, not %d")
user, err = ucache.Get(newUserID) user, err = uc.Get(newUserID)
recordMustExist(t, err, "Couldn't find UID #%d in the cache", newUserID) recordMustExist(t, err, "Couldn't find UID #%d in the cache", newUserID)
expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
} }
@ -188,24 +188,24 @@ func userStoreTest(t *testing.T, newUserID int) {
userList, _ = c.Users.BulkGetMap([]int{1, uid}) userList, _ = c.Users.BulkGetMap([]int{1, uid})
expect(t, len(userList) == 2, fmt.Sprintf("Returned map should have two results, not %d", len(userList))) expect(t, len(userList) == 2, fmt.Sprintf("Returned map should have two results, not %d", len(userList)))
if ucache != nil { if uc != nil {
expectIntToBeX(t, ucache.Length(), 2, "User cache length should be 2, not %d") expectIntToBeX(t, uc.Length(), 2, "User cache length should be 2, not %d")
user, err = ucache.Get(1) user, err = uc.Get(1)
recordMustExist(t, err, "Couldn't find UID #%d in the cache", 1) recordMustExist(t, err, "Couldn't find UID #%d in the cache", 1)
expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == 1, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
user, err = ucache.Get(newUserID) user, err = uc.Get(newUserID)
recordMustExist(t, err, "Couldn't find UID #%d in the cache", newUserID) recordMustExist(t, err, "Couldn't find UID #%d in the cache", newUserID)
expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
ucache.Flush() uc.Flush()
} }
user, err = c.Users.Get(newUserID) user, err = c.Users.Get(newUserID)
recordMustExist(t, err, "Couldn't find UID #%d", newUserID) recordMustExist(t, err, "Couldn't find UID #%d", newUserID)
expectUser(user, newUserID, "Sam", 5, false, false, false, false) expectUser(user, newUserID, "Sam", 5, false, false, false, false)
if ucache != nil { if uc != nil {
expectIntToBeX(t, ucache.Length(), 1, "User cache length should be 1, not %d") expectIntToBeX(t, uc.Length(), 1, "User cache length should be 1, not %d")
user, err = ucache.Get(newUserID) user, err = uc.Get(newUserID)
recordMustExist(t, err, "Couldn't find UID #%d in the cache", newUserID) recordMustExist(t, err, "Couldn't find UID #%d in the cache", newUserID)
expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID)) expect(t, user.ID == newUserID, fmt.Sprintf("user.ID does not match the requested UID. Got '%d' instead.", user.ID))
} }
@ -216,9 +216,9 @@ func userStoreTest(t *testing.T, newUserID int) {
// ? - What if we change the caching mechanism so it isn't hard purged and reloaded? We'll deal with that when we come to it, but for now, this is a sign of a cache bug // ? - What if we change the caching mechanism so it isn't hard purged and reloaded? We'll deal with that when we come to it, but for now, this is a sign of a cache bug
afterUserFlush := func(uid int) { afterUserFlush := func(uid int) {
if ucache != nil { if uc != nil {
expectIntToBeX(t, ucache.Length(), 0, "User cache length should be 0, not %d") expectIntToBeX(t, uc.Length(), 0, "User cache length should be 0, not %d")
_, err = ucache.Get(uid) _, err = uc.Get(uid)
recordMustNotExist(t, err, "UID #%d shouldn't be in the cache", uid) recordMustNotExist(t, err, "UID #%d shouldn't be in the cache", uid)
} }
} }

View File

@ -7,8 +7,8 @@
console.log("resp",resp); console.log("resp",resp);
return; return;
} }
resp.text().then(data => eval(data)); resp.text().then(dat => eval(dat));
}) })
.catch(err => console.log("err", err)); .catch(e => console.log("e",e));
}); });
})() })()

View File

@ -10,10 +10,10 @@
<a id="poweredByName"href="https://github.com/Azareal/Gosora">{{lang "footer_powered_by"}}</a><span id="poweredByDash"> - </span><span id="poweredByMaker">{{lang "footer_made_with_love"}}</span> <a id="poweredByName"href="https://github.com/Azareal/Gosora">{{lang "footer_powered_by"}}</a><span id="poweredByDash"> - </span><span id="poweredByMaker">{{lang "footer_made_with_love"}}</span>
</div> </div>
{{if .CurrentUser.IsAdmin}}<div title="start to before tmpl"class="elapsed">{{.Header.Elapsed1}}</div><div title="start to footer"class="elapsed">{{elapsed .Header.StartedAt}}</div>{{end}} {{if .CurrentUser.IsAdmin}}<div title="start to before tmpl"class="elapsed">{{.Header.Elapsed1}}</div><div title="start to footer"class="elapsed">{{elapsed .Header.StartedAt}}</div>{{end}}
<form action="/theme/" method="post"> <form action="/theme/"method="post">
<div id="themeSelector"> <div id="themeSelector">
<select id="themeSelectorSelect" name="theme" aria-label="{{lang "footer_theme_selector_aria"}}">{{range .Header.Themes}}{{if not .HideFromThemes}} <select id="themeSelectorSelect"name="theme"aria-label="{{lang "footer_theme_selector_aria"}}">{{range .Header.Themes}}{{if not .HideFromThemes}}
<option value="{{.Name}}"{{if eq $.Header.Theme.Name .Name}} selected{{end}}>{{.FriendlyName}}</option> <option value="{{.Name}}"{{if eq $.Header.Theme.Name .Name}}selected{{end}}>{{.FriendlyName}}</option>
{{end}}{{end}}</select> {{end}}{{end}}</select>
<noscript><input type="submit"></noscript> <noscript><input type="submit"></noscript>
</div> </div>

View File

@ -13,7 +13,7 @@
<script src="/s/jquery-3.1.1.min.js"></script> <script src="/s/jquery-3.1.1.min.js"></script>
{{range .Header.Scripts}} {{range .Header.Scripts}}
<script src="/s/{{.}}"></script>{{end}} <script src="/s/{{.}}"></script>{{end}}
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <meta name="viewport"content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
{{if .Header.MetaDesc}}<meta name="description"content="{{.Header.MetaDesc}}">{{end}} {{if .Header.MetaDesc}}<meta name="description"content="{{.Header.MetaDesc}}">{{end}}
{{/** TODO: Have page / forum / topic level tags and descriptions below as-well **/}} {{/** TODO: Have page / forum / topic level tags and descriptions below as-well **/}}
<meta property="og:type"content="website"> <meta property="og:type"content="website">
@ -23,20 +23,20 @@
{{if .OGDesc}}<meta property="og:description"content="{{.OGDesc}}"> {{if .OGDesc}}<meta property="og:description"content="{{.OGDesc}}">
<meta property="twitter:description"content="{{.OGDesc}}">{{end}} <meta property="twitter:description"content="{{.OGDesc}}">{{end}}
{{if .GoogSiteVerify}}<meta name="google-site-verification"content="{{.GoogSiteVerify}}">{{end}} {{if .GoogSiteVerify}}<meta name="google-site-verification"content="{{.GoogSiteVerify}}">{{end}}
<link rel="search" type="application/opensearchdescription+xml" title="{{.Header.Site.Name}}" href="/opensearch.xml"> <link rel="search"type="application/opensearchdescription+xml"title="{{.Header.Site.Name}}"href="/opensearch.xml">
</head> </head>
<body> <body>
{{/**{{if not .CurrentUser.IsSuperMod}}<style>.supermod_only { display: none !important; }</style>{{end}}**/}}{{flush}} {{/**{{if not .CurrentUser.IsSuperMod}}<style>.supermod_only { display: none !important; }</style>{{end}}**/}}{{flush}}
<div id="container" class="container"> <div id="container"class="container">
{{/**<!--<div class="navrow">-->**/}} {{/**<!--<div class="navrow">-->**/}}
<div class="left_of_nav">{{dock "leftOfNav" .Header }}</div> <div class="left_of_nav">{{dock "leftOfNav" .Header }}</div>
<nav class="nav"> <nav class="nav">
<div class="move_left"> <div class="move_left">
<div class="move_right"> <div class="move_right">
<ul id="main_menu" class="zone_{{.Header.Zone}}">{{/** TODO: Have the theme control whether the long or short form of the name is used **/}} <ul id="main_menu"class="zone_{{.Header.Zone}}">{{/** TODO: Have the theme control whether the long or short form of the name is used **/}}
<li id="menu_overview" class="menu_left"><a href="/" rel="home">{{if eq .Header.Theme.Name "nox"}}{{.Header.Site.Name}}{{else}}{{.Header.Site.ShortName}}{{end}}</a></li> <li id="menu_overview"class="menu_left"><a href="/"rel="home">{{if eq .Header.Theme.Name "nox"}}{{.Header.Site.Name}}{{else}}{{.Header.Site.ShortName}}{{end}}</a></li>
{{dock "topMenu" .Header }} {{dock "topMenu" .Header }}
<li class="menu_left menu_hamburger" title="{{lang "menu_hamburger_tooltip"}}"><a></a></li> <li class="menu_left menu_hamburger"title="{{lang "menu_hamburger_tooltip"}}"><a></a></li>
</ul> </ul>
</div> </div>
</div><div style="clear:both;"></div> </div><div style="clear:both;"></div>
@ -56,7 +56,7 @@
{{/**<!--</div>-->**/}} {{/**<!--</div>-->**/}}
<div class="midRow"> <div class="midRow">
<div class="midLeft"></div> <div class="midLeft"></div>
<div id="back" class="zone_{{.Header.Zone}}{{if hasWidgets "rightSidebar" .Header }} shrink_main{{end}}"> <div id="back"class="zone_{{.Header.Zone}}{{if hasWidgets "rightSidebar" .Header }} shrink_main{{end}}">
<div id="main"> <div id="main">
<div class="alertbox initial_alertbox">{{range .Header.NoticeList}} <div class="alertbox initial_alertbox">{{range .Header.NoticeList}}
{{template "notice.html" . }}{{end}} {{template "notice.html" . }}{{end}}

View File

@ -5,7 +5,7 @@
{{range .ItemList}} {{range .ItemList}}
<div class="rowitem editable_parent"> <div class="rowitem editable_parent">
<span class="panel_plugin_meta"> <span class="panel_plugin_meta">
<a{{if .URL}} href="{{.URL}}" {{end}}class="editable_block" class="panel_upshift">{{.Name}}</a><br> <a {{if .URL}}href="{{.URL}}"{{end}}class="editable_block"class="panel_upshift">{{.Name}}</a><br>
<small style="margin-left:2px;">{{lang "panel_plugins_author_prefix"}}{{.Author}}</small> <small style="margin-left:2px;">{{lang "panel_plugins_author_prefix"}}{{.Author}}</small>
</span> </span>
<span class="to_right"> <span class="to_right">