Browse Source

fixing golint issues to try to figure out test flakiness

pull/8/head
Stephen Searles 2 years ago
parent
commit
029d1ed5b3
5 changed files with 28 additions and 21 deletions
  1. 5
    1
      caddyhugo.go
  2. 6
    5
      doc_test.go
  3. 6
    6
      http.go
  4. 5
    3
      media.go
  5. 6
    6
      templates.go

+ 5
- 1
caddyhugo.go View File

@@ -4,7 +4,6 @@ import (
"fmt"
"html/template"
"net/http"
_ "net/http/pprof"
"os/exec"
"path/filepath"
"strings"
@@ -31,6 +30,7 @@ func init() {
// ... there are others. See the godoc.
}

// CaddyHugo implements the plugin
type CaddyHugo struct {
ServerType string
Site *httpserver.SiteConfig
@@ -49,6 +49,7 @@ type CaddyHugo struct {
ltime uint64
}

// Build rebuilds the cached state of the site. TODO: determine if this republishes
func (ch *CaddyHugo) Build() error {
err := ch.HugoSites.Build(hugolib.BuildCfg{ResetState: true})
if err != nil {
@@ -58,6 +59,7 @@ func (ch *CaddyHugo) Build() error {
return nil
}

// BasePath returns the directory that the CaddyHugo internal/author pages are under
func (ch *CaddyHugo) BasePath() string {
return "/hugo"
}
@@ -71,6 +73,7 @@ func (ch *CaddyHugo) docFilename(orig string) string {
return filepath.Join(ch.Dir, docname(orig))
}

// Publish really renders new content into the public directory
func (ch *CaddyHugo) Publish() error {
cmd := exec.Command("hugo")
cmd.Dir = ch.Dir
@@ -82,6 +85,7 @@ func (ch *CaddyHugo) Publish() error {
return nil
}

// TmplData collects data for template execution
func (ch *CaddyHugo) TmplData(r *http.Request, docref *docref) interface{} {
var doc *acedoc.Document
if docref != nil {

+ 6
- 5
doc_test.go View File

@@ -14,23 +14,23 @@ import (
)

type World struct {
CH CaddyHugo
CH *CaddyHugo
BlogFolder string
}

func (w World) Clean() {
func (w *World) Clean() {
if w.BlogFolder != "" {
os.RemoveAll(w.BlogFolder)
}
}

func NewWorld(t *testing.T) World {
func NewWorld(t *testing.T) *World {
dir, err := ioutil.TempDir("", "caddy-hugo2-test-")
if err != nil {
t.Fatalf("error initializing test environment: %v", err)
}

w := World{BlogFolder: dir}
w := &World{BlogFolder: dir}

cmd := exec.Command("hugo", "new", "site", dir)
cmd.Dir = dir
@@ -39,6 +39,7 @@ func NewWorld(t *testing.T) World {
t.Fatalf("error initializing test site: %v\n\n%v", err, string(out))
}

w.CH = &CaddyHugo{}
w.CH.Setup(dir)

return w
@@ -232,7 +233,7 @@ func TestDeltasDouble(t *testing.T) {
// send the second message, via clientB
clientB.ReceiveJSON(w.CH.Message(acedoc.Insert(0, 0, "b")))

time.Sleep(100 * time.Millisecond)
time.Sleep(200 * time.Millisecond)

clientA.mtx.Lock()
clientB.mtx.Lock()

+ 6
- 6
http.go View File

@@ -69,7 +69,7 @@ func (ch *CaddyHugo) ServeHTTPWithNext(next httpserver.Handler, c *caddy.Control
return 404, nil
}

func (ch CaddyHugo) ServeNewContent(w http.ResponseWriter, r *http.Request) (int, error) {
func (ch *CaddyHugo) ServeNewContent(w http.ResponseWriter, r *http.Request) (int, error) {
name := r.FormValue("name")
ctype := r.FormValue("type")

@@ -83,7 +83,7 @@ func (ch CaddyHugo) ServeNewContent(w http.ResponseWriter, r *http.Request) (int
http.Redirect(w, r, filepath.Join("/hugo/edit/", "content", filename), http.StatusFound)
return http.StatusFound, nil
}
func (ch CaddyHugo) Middleware(c *caddy.Controller) httpserver.Middleware {
func (ch *CaddyHugo) Middleware(c *caddy.Controller) httpserver.Middleware {
return func(next httpserver.Handler) httpserver.Handler {
return httpserver.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
return ch.ServeHTTPWithNext(next, c, w, r)
@@ -91,11 +91,11 @@ func (ch CaddyHugo) Middleware(c *caddy.Controller) httpserver.Middleware {
}
}

func (ch CaddyHugo) Auth(r *http.Request) bool {
func (ch *CaddyHugo) Auth(r *http.Request) bool {
return true
}

func (ch CaddyHugo) Match(r *http.Request) bool {
func (ch *CaddyHugo) Match(r *http.Request) bool {
if strings.HasPrefix(r.URL.Path, "/media/") {
return true
}
@@ -107,7 +107,7 @@ func (ch CaddyHugo) Match(r *http.Request) bool {
return strings.HasPrefix(r.URL.Path, "/hugo/")
}

func (ch CaddyHugo) Admin() httpserver.Handler {
func (ch *CaddyHugo) Admin() httpserver.Handler {
return httpserver.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
err := ch.adminTmpl.Execute(w, ch.TmplData(r, nil))
if err != nil {
@@ -120,7 +120,7 @@ func (ch CaddyHugo) Admin() httpserver.Handler {
})
}

func (ch CaddyHugo) AuthorHome() httpserver.Handler {
func (ch *CaddyHugo) AuthorHome() httpserver.Handler {
return httpserver.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
td := ch.TmplData(r, nil)
err := ch.authorTmpl.Execute(w, td)

+ 5
- 3
media.go View File

@@ -3,9 +3,9 @@ package caddyhugo
import (
"fmt"
"image"
_ "image/gif"
_ "image/gif" // for processing images
"image/jpeg"
_ "image/png"
_ "image/png" // for processing images
"io"
"net/http"
"os"
@@ -217,6 +217,9 @@ func (ch *CaddyHugo) uploadMedia(w http.ResponseWriter, r *http.Request) (int, e

for {
part, err := mr.NextPart()
if err == io.EOF {
break
}
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return 400, nil
@@ -344,7 +347,6 @@ func parseSizeString(str string, actual image.Rectangle) (image.Rectangle, error
// w was the only dimension given, so set it to the greater dimension
// of the actual image size
if actual.Dx() > actual.Dy() {
w = w
h = 0
} else {
h = w

+ 6
- 6
templates.go View File

@@ -14,11 +14,11 @@ import (
"github.com/mholt/caddy/caddyhttp/httpserver"
)

func (t tmplData) Content() ([]Content, error) {
func (t *tmplData) Content() ([]Content, error) {
return GetContent(t.Site.Root, t.HugoSites)
}

func (t tmplData) ContentTypes() ([]string, error) {
func (t *tmplData) ContentTypes() ([]string, error) {
nameMap := map[string]struct{}{"default": struct{}{}}

names, err := t.contentTypes(path.Join(t.Site.Root, "archetypes"))
@@ -45,7 +45,7 @@ func (t tmplData) ContentTypes() ([]string, error) {
return out, nil
}

func (t tmplData) contentTypes(dir string) ([]string, error) {
func (t *tmplData) contentTypes(dir string) ([]string, error) {
layoutDir, err := os.Open(path.Join(t.Site.Root, "archetypes"))
if err != nil {
fmt.Println("opening layout dir", err)
@@ -65,12 +65,12 @@ func (t tmplData) contentTypes(dir string) ([]string, error) {
type tmplData struct {
Site *httpserver.SiteConfig
R *http.Request
CaddyHugo
*CaddyHugo
Doc *acedoc.Document
docref *docref
}

func (t tmplData) LoadContent() (string, error) {
func (t *tmplData) LoadContent() (string, error) {
return t.Doc.Contents(), nil
}

@@ -79,7 +79,7 @@ func baseNoExt(name string) string {
return base[:len(base)-len(path.Ext(base))]
}

func (t tmplData) IframeSource() string {
func (t *tmplData) IframeSource() string {
name := baseNoExt(t.docref.name)
ctype := baseNoExt(path.Dir(t.docref.name))
if ctype == "content" {

Loading…
Cancel
Save