mirror of https://github.com/status-im/consul.git
46 lines
798 B
Go
46 lines
798 B
Go
|
package agent
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"io"
|
||
|
"io/ioutil"
|
||
|
"net/http"
|
||
|
"net/http/httptest"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestUiIndex(t *testing.T) {
|
||
|
dir, srv := makeHTTPServer(t)
|
||
|
defer os.RemoveAll(dir)
|
||
|
defer srv.Shutdown()
|
||
|
defer srv.agent.Shutdown()
|
||
|
|
||
|
// Create file
|
||
|
path := filepath.Join(srv.uiDir, "my-file")
|
||
|
ioutil.WriteFile(path, []byte("test"), 777)
|
||
|
|
||
|
// Register node
|
||
|
req, err := http.NewRequest("GET", "/ui/my-file", nil)
|
||
|
if err != nil {
|
||
|
t.Fatalf("err: %v", err)
|
||
|
}
|
||
|
|
||
|
// Make the request
|
||
|
resp := httptest.NewRecorder()
|
||
|
srv.UiIndex(resp, req)
|
||
|
|
||
|
// Verify teh response
|
||
|
if resp.Code != 200 {
|
||
|
t.Fatalf("bad: %v", resp)
|
||
|
}
|
||
|
|
||
|
// Verify the body
|
||
|
out := bytes.NewBuffer(nil)
|
||
|
io.Copy(out, resp.Body)
|
||
|
if string(out.Bytes()) != "test" {
|
||
|
t.Fatalf("bad: %s", out.Bytes())
|
||
|
}
|
||
|
}
|