mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-13 14:39:28 +00:00
Implemented version check
Updated readme
This commit is contained in:
58
src/go/lib/versioncheck/version_check_test.go
Normal file
58
src/go/lib/versioncheck/version_check_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package versioncheck
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCheckUpdates(t *testing.T) {
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, _ := ioutil.ReadAll(r.Body)
|
||||
m := strings.Split(string(body), ";")
|
||||
|
||||
advices := []Advice{
|
||||
Advice{
|
||||
Hash: m[0],
|
||||
ToolName: m[1],
|
||||
Advice: "There is a new version",
|
||||
},
|
||||
}
|
||||
|
||||
buf, _ := json.Marshal(advices)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprint(w, string(buf))
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
msg, err := CheckUpdates(ts.URL, "pt-test", "2.2.18")
|
||||
if err != nil {
|
||||
t.Errorf("error while checking %s", err)
|
||||
}
|
||||
if msg == "" {
|
||||
t.Error("got empty response")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEmptyResponse(t *testing.T) {
|
||||
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "")
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
msg, err := CheckUpdates(ts.URL, "pt-test", "2.2.18")
|
||||
if err == nil {
|
||||
t.Error("response should return error due to empty body")
|
||||
}
|
||||
if msg != "" {
|
||||
t.Error("response should return error due to empty body")
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user