-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
48 lines (40 loc) · 1.1 KB
/
common.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
package yamlhound
import (
"errors"
"fmt"
"os"
"gopkg.in/yaml.v3"
)
// unmarshallCheck checks if the YAML file is not unmarshalled.
func (y *YAMLTracer) unmarshallCheck() error {
if fmt.Sprintf("%T", y.UnmYAML) != "map[string]interface {}" {
// - or you are probably using an older version of the gopkg.in/yaml.v3
// package
return errors.New("unmarshalization failure")
}
// - an empty YAML file
if len(y.UnmYAML) == 0 {
return errors.New("unmarshalization failure or an empty YAML file")
}
return nil
}
// footprintsCheck cheks if the YAMLTracer.Footprints are not defined. There
// must be at least one YAML key or series of consecutive keys provided.
func (y *YAMLTracer) footprintsCheck() error {
if len(y.Footprints) < 1 {
return errors.New("no traces to follow")
}
return nil
}
// Helper functions
// yamlReader is a helper function for the execution of the tests.
func yamlReader(f string, c *map[string]interface{}) error {
yamlFile, err := os.ReadFile(f)
if err != nil {
return err
}
if err := yaml.Unmarshal([]byte(yamlFile), &c); err != nil {
return err
}
return nil
}