When I declare the string as a var in the function using os.Open I don't get the error.
Either the absolute path or relative path will work with a string declared in that function.
I've checked that the value of the string is the same with == (which after the os.Open the string's value is somehow the returned String).
Here is some simplified code to help explain this. I feel like I'm going nuts, lol:
func (s *Scenario) IValidateLastResponseBodyWithResponse(referenceTemplate string) error {
cwd, _ := getCurrentWorkingDirectory()
referenceTemplate = strings.TrimSpace(referenceTemplate)
referenceTemplateTest := "CHICH.json"
// fileToOpen := strings.Clone(referenceTemplate) // This blows up with file name too long
// fileToOpen := referenceTemplateTest // This blows up with file name too long
// fileToOpen := "CHICH.json" // This works
fileToOpen := strings.Clone(referenceTemplateTest) // This works
if referenceTemplate != referenceTemplateTest {
err := fmt.Errorf("STRINGS ARE NOT THE SAME: %v | %v | %v", strings.Compare(referenceTemplate, referenceTemplateTest), referenceTemplate, referenceTemplateTest)
return err
// Interestingly this always fails after the file open, no matter the value of fileToOpen with the second $v being the contents of the JSON file
// If I comment this out the two last fileToOpen variables work and the test completed with no errors.
}
fileContent, _ := os.Open(cwd + "/test/response/" + fileToOpen)
if err != nil {
fmtErr := fmt.Errorf("WHACKDOODLE: %v", err)
return fmtErr
}
defer fileContent.Close()
byteResult, _ := io.ReadAll(fileContent)
...
...
...
Has anyone seen this before?