-
Notifications
You must be signed in to change notification settings - Fork 11
/
main_test.go
37 lines (28 loc) · 1.06 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Bartłomiej Płotka @bwplotka
// Licensed under the Apache License 2.0.
package main
import (
"os"
"testing"
"github.com/efficientgo/core/testutil"
)
func TestValidateAnchorDir(t *testing.T) {
pwd, err := os.Getwd()
testutil.Ok(t, err)
// Consider parametrizing this.
anchorDir, err := validateAnchorDir("", []string{})
testutil.Ok(t, err)
testutil.Equals(t, pwd, anchorDir)
anchorDir, err = validateAnchorDir("/home", []string{})
testutil.Ok(t, err)
testutil.Equals(t, "/home", anchorDir)
anchorDir, err = validateAnchorDir(".", []string{})
testutil.Ok(t, err)
testutil.Equals(t, pwd, anchorDir)
_, err = validateAnchorDir("/root", []string{"/root/something.md", "/home/something/file.md", "/root/a/b/c/file.md"})
testutil.NotOk(t, err)
testutil.Equals(t, "anchorDir \"/root\" is not in path of provided file \"/home/something/file.md\"", err.Error())
anchorDir, err = validateAnchorDir("/root", []string{"/root/something.md", "/root/something/file.md", "/root/a/b/c/file.md"})
testutil.Ok(t, err)
testutil.Equals(t, "/root", anchorDir)
}