diff --git a/backend/server/server.go b/backend/server/server.go index ff62af6..086007d 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -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() { diff --git a/backend/server/server_test.go b/backend/server/server_test.go index df36af7..a609ce5 100644 --- a/backend/server/server_test.go +++ b/backend/server/server_test.go @@ -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 diff --git a/client/lib/lib_test.go b/client/lib/lib_test.go index 560befa..49d5f10 100644 --- a/client/lib/lib_test.go +++ b/client/lib/lib_test.go @@ -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 {