37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package build
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// init adds the Gemini output to the tests of the output folder in output_test.go.
|
|
func init() {
|
|
extraBuilders["gemini"] = func(site string) func(string, bool) ([]string, error) {
|
|
return func(out string, clean bool) ([]string, error) {
|
|
r, err := BuildGemini(GeminiOptions{SiteDir: site, OutDir: out, Version: "1.2.3", Now: fixedNow, Clean: clean, Language: "en"})
|
|
return r.Stale, err
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGeminiCleanRefusesAFolderThatHoldsTheSite checks that -clean never empties the folder of the site, or one above it.
|
|
func TestGeminiCleanRefusesAFolderThatHoldsTheSite(t *testing.T) {
|
|
parent := t.TempDir()
|
|
site := filepath.Join(parent, "site")
|
|
for rel, text := range withFiles(nil) {
|
|
put(t, site, rel, text)
|
|
}
|
|
put(t, parent, motorinoMarker, "x")
|
|
for _, out := range []string{site, parent} {
|
|
if _, err := BuildGemini(GeminiOptions{SiteDir: site, OutDir: out, Now: fixedNow, Clean: true}); err == nil || !strings.Contains(err.Error(), "site") {
|
|
t.Errorf("BuildGemini into %s: error = %v, want one about the site", out, err)
|
|
}
|
|
}
|
|
if !exists(t, site, "site.json") {
|
|
t.Error("the site is gone")
|
|
}
|
|
}
|