1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api: add COMMENTO_STATIC environment variable

Closes https://gitlab.com/commento/commento-ce/issues/2
This commit is contained in:
Adhityaa
2018-06-09 13:57:47 +05:30
parent 88165504f3
commit 432ffeebb3
6 changed files with 103 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"os"
"testing"
"path/filepath"
)
func TestParseConfigBasics(t *testing.T) {
@ -31,3 +32,55 @@ func TestParseConfigBasics(t *testing.T) {
return
}
}
func TestParseConfigStatic(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
if err := parseConfig(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err)
return
}
binPath, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
t.Errorf("cannot load binary path: %v", err)
return
}
if os.Getenv("STATIC") != binPath {
t.Errorf("COMMENTO_STATIC != %s when unset", binPath)
return
}
os.Setenv("COMMENTO_STATIC", "/usr/")
if err := parseConfig(); err != nil {
t.Errorf("unexpected error when parsing config: %v", err)
return
}
if os.Getenv("STATIC") != "/usr" {
t.Errorf("COMMENTO_STATIC != /usr when unset")
return
}
}
func TestParseConfigStaticDNE(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
os.Setenv("COMMENTO_STATIC", "/does/not/exist/surely/")
if err := parseConfig(); err == nil {
t.Errorf("expected error not found when a non-existant directory is used")
return
}
}
func TestParseConfigStaticNotADirectory(t *testing.T) {
os.Setenv("COMMENTO_ORIGIN", "https://commento.io")
os.Setenv("COMMENTO_STATIC", os.Args[0])
if err := parseConfig(); err != errorNotADirectory {
t.Errorf("expected error not found when a file is used")
return
}
}