Files
summercms/modules/sunrise/example_test.go

36 lines
836 B
Go

package sunrise_test
import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"git.golem15.com/golem15/summercms/modules/sunrise"
)
func newScript(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
_, _ = w.Write(sunrise.Script())
}
func Example() {
srv := httptest.NewServer(http.HandlerFunc(newScript))
defer srv.Close()
resp, err := http.Get(srv.URL + "/new")
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
var body bytes.Buffer
_, _ = body.ReadFrom(resp.Body)
fmt.Println(resp.StatusCode, resp.Header.Get("Content-Type"))
fmt.Println(bytes.Equal(body.Bytes(), sunrise.Script()), bytes.HasPrefix(body.Bytes(), []byte("#!")))
// Output:
// 200 text/plain; charset=utf-8
// true true
}