fup/minicheddar: add basic spawn test
This commit is contained in:
parent
b7cd0d0e29
commit
c187956f19
3 changed files with 58 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
{ pkgs, ... }:
|
{ depot, pkgs, ... }:
|
||||||
let
|
let
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
in
|
in
|
||||||
|
@ -12,6 +12,10 @@ pkgs.buildGoModule {
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
depot.third_party.cheddar
|
||||||
|
];
|
||||||
|
|
||||||
vendorSha256 = "sha256:0myd1p61q777ybbwdz8k4nbchh2hv1yr8008061m3gc44s3gsphx";
|
vendorSha256 = "sha256:0myd1p61q777ybbwdz8k4nbchh2hv1yr8008061m3gc44s3gsphx";
|
||||||
|
|
||||||
meta = with pkgs.lib; {
|
meta = with pkgs.lib; {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (c *Cheddar) Markdown(ctx context.Context, text string) (safehtml.HTML, err
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return safehtml.HTML{}, fmt.Errorf("markdown rendering request returned status %s; not OK", resp.StatusCode)
|
return safehtml.HTML{}, fmt.Errorf("markdown rendering request returned status %d; not OK", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
var respData markdownReqResp
|
var respData markdownReqResp
|
||||||
|
@ -96,7 +96,7 @@ func (c *Cheddar) Code(ctx context.Context, filename, theme, text string) (safeh
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return safehtml.HTML{}, fmt.Errorf("code rendering request returned status %s; not OK", resp.StatusCode)
|
return safehtml.HTML{}, fmt.Errorf("code rendering request returned status %d; not OK", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
var respData codeResp
|
var respData codeResp
|
||||||
|
|
51
web/fup/minicheddar/minicheddar_test.go
Normal file
51
web/fup/minicheddar/minicheddar_test.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
// SPDX-FileCopyrightText: 2021 Luke Granger-Brown <depot@lukegb.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package minicheddar_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"hg.lukegb.com/lukegb/depot/web/fup/minicheddar"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSpawn(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
t.Cleanup(cancel)
|
||||||
|
|
||||||
|
cpath, err := exec.LookPath("cheddar")
|
||||||
|
if err != nil {
|
||||||
|
t.Skip("couldn't find cheddar")
|
||||||
|
}
|
||||||
|
|
||||||
|
cheddar, err := minicheddar.Spawn(ctx, cpath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("minicheddar.Spawn: %v", err)
|
||||||
|
}
|
||||||
|
defer cheddar.Close()
|
||||||
|
|
||||||
|
t.Run("Code", func(t *testing.T) {
|
||||||
|
html, err := cheddar.Code(ctx, "index.html", "Some Theme", "<!DOCTYPE html>\n<html>\n")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("minicheddar.Code: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if html.String() == "" {
|
||||||
|
t.Fatalf("minicheddar.Code = %q; want non-empty string", html.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Markdown", func(t *testing.T) {
|
||||||
|
html, err := cheddar.Markdown(ctx, "* Bulleted\n* Lists\n")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("minicheddar.Markdown: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if html.String() == "" {
|
||||||
|
t.Fatalf("minicheddar.Markdown = %q; want non-empty string", html.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue