New RSSFeed doesn't auto update, server callback adds to feed pool, monitor callback updates feed
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"syscall"
|
||||
@@ -18,7 +19,7 @@ func Test_Server(t *testing.T) {
|
||||
|
||||
for _, _ = range cases {
|
||||
var err error
|
||||
s, err := New(testPort)
|
||||
s, err := New(testPort, func(string, string, string, time.Duration) {})
|
||||
if err != nil {
|
||||
t.Errorf("failed to create server: %v", err)
|
||||
}
|
||||
@@ -33,19 +34,29 @@ func Test_Server(t *testing.T) {
|
||||
if err := checkStatus("GET", "api/feed", http.StatusOK); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("POST", "api/feed", http.StatusOK); err != nil {
|
||||
if err := checkStatus("POST", "api/feed", http.StatusBadRequest); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("PUT", "api/feed", http.StatusOK); err != nil {
|
||||
if err := checkStatus("PUT", "api/feed", http.StatusBadRequest, "invalid json"); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("POST", "api/feed", http.StatusBadRequest, `{"url":"hello/world", "refresh":"1m"}`); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := checkStatus("PUT", "api/feed", http.StatusOK, `{"url":"localhost:1234", "refresh":"1m"}`); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
||||
}
|
||||
}
|
||||
|
||||
func checkStatus(method, path string, code int) error {
|
||||
func checkStatus(method, path string, code int, body ...string) error {
|
||||
b := bytes.NewBuffer(nil)
|
||||
if len(body) > 0 {
|
||||
b = bytes.NewBufferString(body[0])
|
||||
}
|
||||
client := &http.Client{}
|
||||
r, _ := http.NewRequest(method, "http://localhost:"+testPort+"/"+path, nil)
|
||||
r, _ := http.NewRequest(method, "http://localhost:"+testPort+"/"+path, b)
|
||||
resp, err := client.Do(r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to %v server: %v", method, err)
|
||||
|
||||
Reference in New Issue
Block a user