-
Notifications
You must be signed in to change notification settings - Fork 3
/
configuration_test.go
76 lines (68 loc) · 2.14 KB
/
configuration_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
// Copyright 2018-2022 VirtualTam.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
package ccache
import (
"testing"
"github.com/alecthomas/units"
)
func TestParseConfiguration(t *testing.T) {
cases := []struct {
tname string
input string
want Configuration
}{
{
tname: "configured via environment and file (without size unit)",
input: `(environment) cache_dir = /home/cached/.ccache
(/home/cached/.ccache/ccache.conf) max_size = 5.0G
`,
want: Configuration{
CacheDirectory: "/home/cached/.ccache",
PrimaryConfig: "/home/cached/.ccache/ccache.conf",
MaxCacheSize: "5.0GB",
MaxCacheSizeBytes: units.MetricBytes(5000000000),
},
},
{
tname: "configured via file (without size unit)",
input: `(default) cache_dir = /home/cached/.ccache
(/home/cached/.ccache/ccache.conf) max_size = 15.0G
`,
want: Configuration{
CacheDirectory: "/home/cached/.ccache",
PrimaryConfig: "/home/cached/.ccache/ccache.conf",
MaxCacheSize: "15.0GB",
MaxCacheSizeBytes: units.MetricBytes(15000000000),
},
},
{
tname: "configured via file",
input: `(default) cache_dir = /home/cached/.ccache
(/home/cached/.ccache/ccache.conf) max_size = 17.0 GB
`,
want: Configuration{
CacheDirectory: "/home/cached/.ccache",
PrimaryConfig: "/home/cached/.ccache/ccache.conf",
MaxCacheSize: "17.0GB",
MaxCacheSizeBytes: units.MetricBytes(17000000000),
},
},
}
for _, tc := range cases {
t.Run(tc.tname, func(t *testing.T) {
got, err := ParseConfiguration(tc.input)
if err != nil {
t.Fatalf("want no error, got %q", err)
}
assertConfigurationsEqual(t, got, &tc.want)
})
}
}
func assertConfigurationsEqual(t *testing.T, got, want *Configuration) {
t.Helper()
assertStringFieldEquals(t, "CacheDirectory", got.CacheDirectory, want.CacheDirectory)
assertStringFieldEquals(t, "PrimaryConfig", got.PrimaryConfig, want.PrimaryConfig)
assertStringFieldEquals(t, "MaxCacheSize", got.MaxCacheSize, want.MaxCacheSize)
assertMetricByteFieldEquals(t, "MaxCacheSizeBytes", got.MaxCacheSizeBytes, want.MaxCacheSizeBytes)
}