mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 16:24:00 +01:00
More tests
This commit is contained in:
parent
b92087fc1d
commit
64935391b6
@ -160,17 +160,17 @@ type releaseInfo struct {
|
||||
func updateReleaseVersion() error {
|
||||
resp, err := http.Get("https://api.github.com/repos/ddworken/hishtory/releases/latest")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get latest release version: %v\n", err)
|
||||
return fmt.Errorf("failed to get latest release version: %v", err)
|
||||
}
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read github API response body: %v\n", err)
|
||||
return fmt.Errorf("failed to read github API response body: %v", err)
|
||||
}
|
||||
if resp.StatusCode == 403 && strings.Contains(string(respBody), "API rate limit exceeded for ") {
|
||||
return nil
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("failed to call github API, status_code=%d, body=%#v\n", resp.StatusCode, string(respBody))
|
||||
return fmt.Errorf("failed to call github API, status_code=%d, body=%#v", resp.StatusCode, string(respBody))
|
||||
}
|
||||
var info releaseInfo
|
||||
err = json.Unmarshal(respBody, &info)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ddworken/hishtory/client/data"
|
||||
@ -111,4 +112,24 @@ func TestESubmitThenQuery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Maybe a test for updateReleaseVersion
|
||||
func TestUpdateReleaseVersion(t *testing.T) {
|
||||
// Set up
|
||||
defer shared.BackupAndRestore(t)()
|
||||
InitDB()
|
||||
|
||||
// Check that ReleaseVersion hasn't been set yet
|
||||
if ReleaseVersion != "UNKNOWN" {
|
||||
t.Fatalf("ReleaseVersion isn't as expected: %#v", ReleaseVersion)
|
||||
}
|
||||
|
||||
// Update it
|
||||
err := updateReleaseVersion()
|
||||
if err != nil {
|
||||
t.Fatalf("updateReleaseVersion failed: %v", err)
|
||||
}
|
||||
|
||||
// And check that the new value looks reasonable
|
||||
if !strings.HasPrefix(ReleaseVersion, "v0.") {
|
||||
t.Fatalf("ReleaseVersion isn't as expected: %#v", ReleaseVersion)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user