forked from u-root/u-root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
54 lines (46 loc) · 1.27 KB
/
config_test.go
File metadata and controls
54 lines (46 loc) · 1.27 KB
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
// Copyright 2017-2018 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package diskboot
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/go-test/deep"
)
func TestParseEmpty(t *testing.T) {
config := ParseConfig("/", "/grub.cfg", nil)
if config == nil {
t.Error("Expected non-nil config")
}
if len(config.Entries) > 0 {
t.Error("Expected no entries: got", config.Entries)
}
}
func TestConfigs(t *testing.T) {
// find all saved configs
tests, err := filepath.Glob("testdata/*.json")
if err != nil {
t.Error("Failed to find test config files:", err)
}
for _, test := range tests {
testJSON, err := ioutil.ReadFile(test)
if err != nil {
t.Errorf("Failed to read test json '%v':%v", test, err)
}
testConfigs := make([]*Config, 0)
err = json.Unmarshal(testJSON, &testConfigs)
if err != nil {
t.Errorf("Failed to unmarshall test json '%v':%v", test, err)
}
configPath := strings.TrimRight(test, ".json")
configs := FindConfigs(configPath)
configJSON, _ := json.Marshal(configs)
t.Logf("Configs for %v\n%v", test, string(configJSON))
if diff := deep.Equal(testConfigs, configs); diff != nil {
t.Error(diff)
}
}
}