#Passing string from outside function to to os.Open gives me "file name too long"

4 messages · Page 1 of 1 (latest)

hushed anvil
#

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?

hushed anvil
#

No, this is something else. Just setup another test and it has to be with what godog is returning even though it's type is a string.

#

OK, I obviously need to step away from this for a while, lol. I can not figure out how to get what I'm passing in from the feature file (gherkin) into the test wrapped by godog to be a string (even though it is a string). Debugging tests with feature files doesn't seem to be very easy to do with Goland because of delv and it not bringing the non go directory structure with it into the built with debug binary that it attaches to from some temp dir.

hushed anvil
#

Yep, all I need was to look into the debugger to see another call to the function with an inline doc.