Try again to fix timezone test

This commit is contained in:
David Dworken 2022-04-09 12:57:58 -07:00
parent c52a7f4ae6
commit b92087fc1d
3 changed files with 14 additions and 12 deletions

View File

@ -145,7 +145,10 @@ func init() {
func keepReleaseVersionUpToDate() {
for {
updateReleaseVersion()
err := updateReleaseVersion()
if err != nil {
fmt.Println(err)
}
time.Sleep(10 * time.Minute)
}
}
@ -154,31 +157,28 @@ type releaseInfo struct {
Name string `json:"name"`
}
func updateReleaseVersion() {
func updateReleaseVersion() error {
resp, err := http.Get("https://api.github.com/repos/ddworken/hishtory/releases/latest")
if err != nil {
fmt.Printf("failed to get latest release version: %v\n", err)
return
return fmt.Errorf("failed to get latest release version: %v\n", err)
}
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("failed to read github API response body: %v\n", err)
return
return fmt.Errorf("failed to read github API response body: %v\n", err)
}
if resp.StatusCode == 403 && strings.Contains(string(respBody), "API rate limit exceeded for ") {
// cannot update ReleaseVersion because we exceeded the rate limit, fail silently
return
return nil
}
if resp.StatusCode != 200 {
fmt.Printf("failed to call github API, status_code=%d, body=%#v\n", resp.StatusCode, string(respBody))
return
return fmt.Errorf("failed to call github API, status_code=%d, body=%#v\n", resp.StatusCode, string(respBody))
}
var info releaseInfo
err = json.Unmarshal(respBody, &info)
if err != nil {
fmt.Printf("failed to parse github API response: %v", err)
return fmt.Errorf("failed to parse github API response: %v", err)
}
ReleaseVersion = info.Name
return nil
}
func InitDB() {

View File

@ -110,3 +110,5 @@ func TestESubmitThenQuery(t *testing.T) {
t.Fatalf("Expected to retrieve 2 entries, found %d", len(retrievedEntries))
}
}
// TODO: Maybe a test for updateReleaseVersion

View File

@ -53,7 +53,7 @@ func TestBuildHistoryEntry(t *testing.T) {
if entry.Command != "ls /" {
t.Fatalf("history entry has unexpected command: %v", entry.Command)
}
if !strings.HasPrefix(entry.StartTime.Format(time.RFC3339), "2022-01-09T") {
if !strings.HasPrefix(entry.StartTime.Format(time.RFC3339), "2022-01-09T") && !strings.HasPrefix(entry.StartTime.Format(time.RFC3339), "2022-01-10T") {
t.Fatalf("history entry has incorrect date in the start time: %v", entry.StartTime.Format(time.RFC3339))
}
if entry.StartTime.Unix() != 1641774958 {