-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
86 lines (79 loc) · 2.08 KB
/
config_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"os"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestConfig(t *testing.T) {
t.Parallel()
// TODO: consolidate testing utils for managing temporary directories with
// state_test.go
tmpDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
t.Fatal(err)
}
}()
t.Run("non_existing_config", func(t *testing.T) {
if _, err := readConfig("/does/not/exist"); err != nil {
t.Errorf("Expected no error when reading non-existing file: %s", err)
}
})
t.Run("round_trip", func(t *testing.T) {
path := filepath.Join(tmpDir, "round_trip.json")
c := &config{
MkvUtilServerTarget: "/foo/bar",
}
if err := writeConfig(c, path); err != nil {
t.Error(err)
return
}
readC, err := readConfig(path)
if err != nil {
t.Error(err)
return
}
if !cmp.Equal(c, readC) {
t.Errorf(cmp.Diff(c, readC))
}
})
}
func TestConfigString(t *testing.T) {
t.Parallel()
t.Run("empty", func(t *testing.T) {
t.Parallel()
expected := `MkvUtilServerTarget: <empty>
TcServerTarget: <empty>
DefaultShowTranscodeOutDir: <empty>
DefaultMovieTranscodeOutDir: <empty>
RipCacheServerDir: <empty>
RipCacheLocalDir: <empty>
`
c := &config{}
actual := c.String()
if !cmp.Equal(expected, actual) {
t.Error(cmp.Diff(expected, actual))
}
})
t.Run("set", func(t *testing.T) {
t.Parallel()
expected := `MkvUtilServerTarget: "taters"
TcServerTarget: <empty>
DefaultShowTranscodeOutDir: <empty>
DefaultMovieTranscodeOutDir: <empty>
RipCacheServerDir: <empty>
RipCacheLocalDir: <empty>
`
c := &config{
MkvUtilServerTarget: "taters",
}
actual := c.String()
if !cmp.Equal(expected, actual) {
t.Error(cmp.Diff(expected, actual))
}
})
}