76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestConfig(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
configData := []byte(`
|
|
salt: 'xXxN4CLxXx'
|
|
|
|
authors:
|
|
read@stick.rocketnine.space: 'Read Access'
|
|
check@stick.rocketnine.space: 'Check Access'
|
|
write@stick.rocketnine.space: 'Write Access'
|
|
|
|
notebooks:
|
|
Test Notebook A:
|
|
repo: /home/stick/repo/a
|
|
serve:
|
|
- read@stick.rocketnine.space: read
|
|
- write@stick.rocketnine.space: write
|
|
Test Notebook B:
|
|
repo: /home/stick/repo/b
|
|
serve:
|
|
- check@stick.rocketnine.space: check
|
|
- read@stick.rocketnine.space
|
|
`)
|
|
|
|
c, err := ReadConfigData(configData)
|
|
if err != nil {
|
|
t.Errorf("failed to load config data: %+v", err)
|
|
}
|
|
|
|
if c.Debug != false {
|
|
t.Errorf("failed to read config option Debug: expected %t, got %t", false, c.Debug)
|
|
}
|
|
|
|
if c.Salt != "xXxN4CLxXx" {
|
|
t.Errorf("failed to read config option Salt: expected %s, got %s", "xXxN4CLxXx", c.Salt)
|
|
}
|
|
|
|
expectedAuthors := []*AuthorConfig{
|
|
{Email: "read@stick.rocketnine.space", Name: "Read Access"},
|
|
{Email: "check@stick.rocketnine.space", Name: "Check Access"},
|
|
{Email: "write@stick.rocketnine.space", Name: "Write Access"}}
|
|
for _, expectedAuthor := range expectedAuthors {
|
|
found := 0
|
|
for _, author := range c.Authors {
|
|
if author.Email == expectedAuthor.Email && author.Name == expectedAuthor.Name {
|
|
found++
|
|
}
|
|
}
|
|
if found != 1 {
|
|
t.Errorf("failed to read config option Author: expected 1 %v, got %d", expectedAuthor, found)
|
|
}
|
|
}
|
|
|
|
expectedNotebooks := []*NotebookConfig{
|
|
{Label: "Test Notebook A", Repo: "/home/stick/repo/a", Serve: map[string]int{"read@stick.rocketnine.space": AuthorAccessRead, "write@stick.rocketnine.space": AuthorAccessWrite}},
|
|
{Label: "Test Notebook B", Repo: "/home/stick/repo/b", Serve: map[string]int{"check@stick.rocketnine.space": AuthorAccessCheck, "read@stick.rocketnine.space": AuthorAccessRead}}}
|
|
for _, expectedNotebook := range expectedNotebooks {
|
|
found := 0
|
|
for _, notebook := range c.Notebooks {
|
|
if notebook.Label == expectedNotebook.Label && reflect.DeepEqual(notebook.Serve, expectedNotebook.Serve) && notebook.Repo == expectedNotebook.Repo {
|
|
found++
|
|
}
|
|
}
|
|
if found != 1 {
|
|
t.Errorf("failed to read config option Notebook: expected 1 %v, got %d", expectedNotebook, found)
|
|
}
|
|
}
|
|
}
|