Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 23, 2023
1 parent a6b821b commit 6df820b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Go
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
- name: Install dependencies
run: go get .
- name: Build
run: go build -v ./...
- name: Test with the Go CLI
run: go test
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var md = goldmark.New(
),
)

var templates = template.Must(template.ParseFS(os.DirFS("templates/"), "*.html"))
var templates *template.Template

//go:embed sitemap.xsl
var sitemapXSL []byte
Expand Down Expand Up @@ -427,6 +427,11 @@ func main() {
var err error
timeStart := time.Now()

templates, err = template.ParseFS(os.DirFS("templates/"), "*.html")
if err != nil {
log.Fatal("Error reading templates/ directory: %s", err)
}

site := Site{}

// read config.xml
Expand Down
37 changes: 37 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"strings"
"testing"
)

func TestParseFrontMatter(t *testing.T) {
p := &Page{
Path: "example/content/index.md",
}

if err := parseFrontMatter(p); err != nil {
t.Fatal(err)
}

expectedTitle := "My site"
if p.Title != expectedTitle {
t.Errorf("Invalid title. Expected %v, got %v", expectedTitle, p.Title)
}
}

func TestParseContent(t *testing.T) {
p := &Page{
Path: "example/content/index.md",
}

content, err := p.ParseContent()
if err != nil {
t.Fatal(err)
}

if !strings.Contains(content, "<p>Hey, welcome on my site!</p>") {
t.Errorf("Invalid content. Got %v", content)
}

}

0 comments on commit 6df820b

Please sign in to comment.