github.com/enetx/g@v1.0.80/tests/errors_test.go (about) 1 package g_test 2 3 import ( 4 "testing" 5 6 "github.com/enetx/g" 7 ) 8 9 func TestErrFileNotExist_Error(t *testing.T) { 10 // Create an instance of ErrFileNotExist 11 err := &g.ErrFileNotExist{Msg: "example.txt"} 12 13 // Check if the error message is formatted correctly 14 expectedErrorMsg := "no such file: example.txt" 15 if errMsg := err.Error(); errMsg != expectedErrorMsg { 16 t.Errorf("TestErrFileNotExist_Error: Expected error message '%s', got '%s'", expectedErrorMsg, errMsg) 17 } 18 } 19 20 func TestErrFileClosed_Error(t *testing.T) { 21 // Create an instance of ErrFileClosed 22 err := &g.ErrFileClosed{Msg: "example.txt"} 23 24 // Check if the error message is formatted correctly 25 expectedErrorMsg := "example.txt: file is already closed and unlocked" 26 if errMsg := err.Error(); errMsg != expectedErrorMsg { 27 t.Errorf("TestErrFileClosed_Error: Expected error message '%s', got '%s'", expectedErrorMsg, errMsg) 28 } 29 }