camfish/error_test.go
2024-12-31 01:27:53 -05:00

75 lines
1.3 KiB
Go

package camfish
import "testing"
func TestConfigError (test *testing.T) {
err := ConfigError {
File: "example.conf",
Key: "some-key",
Line: 6,
Column: 20,
Err: ErrNotFound,
}
str := err.Error()
test.Log(str)
if str != "example.conf[some-key]:6:20: not found" {
test.Fatal("not equal")
}
unwrapped := err.Unwrap()
test.Log(unwrapped)
if unwrapped!= ErrNotFound {
test.Fatal("not equal")
}
err = ConfigError {
File: "example.conf",
Line: 6,
Column: 20,
Err: ErrNotFound,
}
str = err.Error()
test.Log(str)
if str != "example.conf:6:20: not found" {
test.Fatal("not equal")
}
err = ConfigError {
Key: "some-key",
Column: 20,
Err: ErrNotFound,
}
str = err.Error()
test.Log(str)
if str != "[some-key]: not found" {
test.Fatal("not equal")
}
err = ConfigError {
File: "example.conf",
Key: "some-key",
Line: 20,
Err: ErrNotFound,
}
str = err.Error()
test.Log(str)
if str != "example.conf[some-key]:20: not found" {
test.Fatal("not equal")
}
err = ConfigError {
Err: ErrNotFound,
}
str = err.Error()
test.Log(str)
if str != "not found" {
test.Fatal("not equal")
}
err = ConfigError { }
str = err.Error()
test.Log(str)
if str != "configuration error" {
test.Fatal("not equal")
}
}