Skip to content

Commit

Permalink
Do encoding negotiation; add hurl integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
infogulch committed Oct 16, 2023
1 parent 0c114ca commit 38c2b62
Show file tree
Hide file tree
Showing 21 changed files with 545 additions and 17 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- uses: gacts/install-hurl@v1

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

- name: Hurl Tests
run: ./test/run.sh

- run: go build -o xtemplate ./bin
- run: go build -o caddy ./caddy

- uses: actions/upload-artifact@v3
with:
name: xtemplate
path: xtemplate

- uses: actions/upload-artifact@v3
with:
name: caddy
path: caddy
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
go.work*
xtemplate*
templates
caddy
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "xtemplate bin",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./bin",
"args": ["--template-root", "integration/templates", "--log", "-4"],
"cwd": "${workspaceFolder}"
}
]
}
16 changes: 12 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

### Features

- [ ] Split xtemplate from caddy so it can be used standalone
- [ ] Refactor router to return `http.Handler`, use custom handler for static files

### Documentation

- [ ] Highlight file server feature
- [ ] Add "Why?" section to readme.
- [ ] Organize docs according to https://diataxis.fr/

### Automation

- Add github workflows
- [ ] Set up go tests
- [ ] Set up hurl tests
- [ ] Publish binaries and release when a git tag is pushed

### Demos
Expand All @@ -33,13 +37,17 @@

# DONE

## v0.1

- [x] Make extrafuncs an array
- Split xtemplate from caddy so it can be used standalone
- [x] Split xtemplate from caddy so it can be used standalone
- [x] Split watcher into a separate component
- [x] Isolate caddy integration into one file
- [x] Split into separate packages `xtemplate` and `xtemplate/caddy`, rename repo to `xtemplate`
- [x] Write basic server based on net/http
- [x] Update docs describe the separate packages
- [x] Integrate a static file server
- [x] Add github automation
- [x] Change file server to actually negotiate accept-encoding
- [x] Set up automation
- [x] Build and upload binaries
- [x] Set up hurl tests
2 changes: 2 additions & 0 deletions integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
report
*.log
11 changes: 11 additions & 0 deletions integration/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
debug
}

:8080 {
route {
xtemplate {
template_root templates
}
}
}
21 changes: 21 additions & 0 deletions integration/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Set up xtemplate server and cleanup
echo "Running xtemplate..."
pushd `dirname "$(readlink -f "$0")"` > /dev/null # cd to the directory where this script is
go run ../bin -log -4 > xtemplate.log & # exec go run in the background
PID=$! # grab the pid
exit() { # define exit handler
sleep 0.1s # wait for stdout to flush
kill $PID # kill the process
popd # cd back to wherever the script was invoked from
}
trap exit EXIT # register exit handler
until grep -q -i 'msg=serving' xtemplate.log # wait for the server to start
do
sleep 0.1
done
echo ""

# Run tests
hurl --continue-on-error --test --report-html report *.hurl
1 change: 1 addition & 0 deletions integration/templates/_hidden.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>You can't see me</p>
Empty file added integration/templates/empty.txt
Empty file.
Binary file added integration/templates/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions integration/templates/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testing
Binary file added integration/templates/file.txt.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions integration/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<link rel="stylesheet" href="/basic.css?hash={{.SRI `/basic.css`}}" integrity="{{.SRI `/basic.css`}}">
<p>Hello world!</p>
236 changes: 236 additions & 0 deletions integration/templates/reset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
p {
background-color: red !important;
}

*,
::after,
::before {
box-sizing: border-box;
border-width: 0;
border-style: solid;
border-color: #e5e7eb;
content: '';
}

html {
line-height: 1.5;
-webkit-text-size-adjust: 100%;
-moz-tab-size: 4;
tab-size: 4;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-feature-settings: normal;
font-variation-settings: normal
}

body {
margin: 0;
line-height: inherit
}

hr {
height: 0;
color: inherit;
border-top-width: 1px
}

abbr:where([title]) {
-webkit-text-decoration: underline dotted;
text-decoration: underline dotted
}

h1,
h2,
h3,
h4,
h5,
h6 {
font-size: inherit;
font-weight: inherit
}

a {
color: inherit;
text-decoration: inherit
}

b,
strong {
font-weight: bolder
}

code,
kbd,
pre,
samp {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 1em
}

small {
font-size: 80%
}

sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline
}

sub {
bottom: -.25em
}

sup {
top: -.5em
}

table {
text-indent: 0;
border-color: inherit;
border-collapse: collapse
}

button,
input,
optgroup,
select,
textarea {
font-family: inherit;
font-feature-settings: inherit;
font-variation-settings: inherit;
font-size: 100%;
font-weight: inherit;
line-height: inherit;
color: inherit;
margin: 0;
padding: 0
}

button,
select {
text-transform: none
}

[type=button],
[type=reset],
[type=submit],
button {
-webkit-appearance: button;
background-color: transparent;
background-image: none
}

:-moz-focusring {
outline: auto
}

:-moz-ui-invalid {
box-shadow: none
}

progress {
vertical-align: baseline
}

::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: auto
}

[type=search] {
-webkit-appearance: textfield;
outline-offset: -2px
}

::-webkit-search-decoration {
-webkit-appearance: none
}

::-webkit-file-upload-button {
-webkit-appearance: button;
font: inherit
}

summary {
display: list-item
}

blockquote,
dd,
dl,
figure,
h1,
h2,
h3,
h4,
h5,
h6,
hr,
p,
pre {
margin: 0
}

fieldset {
margin: 0;
padding: 0
}

legend {
padding: 0
}

menu,
ol,
ul {
list-style: none;
margin: 0;
padding: 0
}

dialog {
padding: 0
}

textarea {
resize: vertical
}

input::placeholder,
textarea::placeholder {
opacity: 1;
color: #9ca3af
}

[role=button],
button {
cursor: pointer
}

:disabled {
cursor: default
}

audio,
canvas,
embed,
iframe,
img,
object,
svg,
video {
display: block;
vertical-align: middle
}

img,
video {
max-width: 100%;
height: auto
}

[hidden] {
display: none
}
Binary file added integration/templates/reset.css.br
Binary file not shown.
Binary file added integration/templates/reset.css.gz
Binary file not shown.
Binary file added integration/templates/standalone.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions integration/templates/visible.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{template "/_hidden.html". }}

<p>And now you can</p>
Loading

0 comments on commit 38c2b62

Please sign in to comment.