...
1
2
3
4 package kusterr
5
6 import (
7 "fmt"
8 "testing"
9 )
10
11 const (
12 filepath = "/path/to/whatever"
13 expected = "YAML file [/path/to/whatever] encounters a format error.\n" +
14 "error converting YAML to JSON: yaml: line 2: found character that cannot start any token\n"
15 )
16
17 func TestYamlFormatError_Error(t *testing.T) {
18 testErr := YamlFormatError{
19 Path: filepath,
20 ErrorMsg: "error converting YAML to JSON: yaml: line 2: found character that cannot start any token",
21 }
22 if testErr.Error() != expected {
23 t.Errorf("Expected : %s\n, but found : %s\n", expected, testErr.Error())
24 }
25 }
26
27 func TestErrorHandler(t *testing.T) {
28 err := fmt.Errorf("error converting YAML to JSON: yaml: line 2: found character that cannot start any token")
29 testErr := Handler(err, filepath)
30 expectedErr := fmt.Errorf("format error message")
31 fmtErr := Handler(expectedErr, filepath)
32 if fmtErr.Error() != expectedErr.Error() {
33 t.Errorf("Expected returning fmt.Error, but found %T", fmtErr)
34 }
35 if _, ok := testErr.(YamlFormatError); !ok {
36 t.Errorf("Expected returning YamlFormatError, but found %T", testErr)
37 }
38 if testErr == nil || testErr.Error() != expected {
39 t.Errorf("Expected : %s\n, but found : %s\n", expected, testErr.Error())
40 }
41 }
42
View as plain text