Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.removeall fails to remove directories sometimes #42187

Closed
cfair-beckman opened this issue Oct 24, 2020 · 1 comment
Closed

os.removeall fails to remove directories sometimes #42187

cfair-beckman opened this issue Oct 24, 2020 · 1 comment

Comments

@cfair-beckman
Copy link

What version of Go are you using (go version)?

go version go1.15.2 linux/amd64

Does this issue reproduce with the latest release?

As far as I know I am on the most recent release

###What operating system and processor architecture are you using (go env)?
Processor: Ryzen 7 1700x
Architecture: AMD64
Operating System: Manjaro Linux 20.1.20

What did you do?

I tried to delete a directory and it failed to delete in a unit test while returning no error

func Test_AddNewUser(t *testing.T) {

ConfigurationFile.UsersDirectory = "./UserResults"
newUser := "Dracula Bramstokers"
newFile := ConfigurationFile.UsersDirectory + PS + "Dracula_Bramstokers.json"
err := AddNewUser(newUser)
assert.Nil(t, err, "This should be nil")
assert.FileExists(t, newFile, "File should have been created")
os.Remove(newFile)

ConfigurationFile.UsersDirectory = "bluhbluh"

newUser = "Dracula Bramstokers"
newFile = ConfigurationFile.UsersDirectory + PS + "Dracula_Bramstokers.json"
err = AddNewUser(newUser)
assert.Nil(t, err, "This should be nil")
assert.FileExists(t, newFile, "File should have been created")
os.RemoveAll("bluhbluh")

}

func Test_ListOfUserResultPaths(t *testing.T) {
ConfigurationFile.UsersDirectory = "UnitTestingUsers"
newUserOne := "Dracula Vampire"
newUserTwo := "Werewolf Wolfie"
newUserThree := "Flying Monkey"
newFileOne := ConfigurationFile.UsersDirectory + PS + newUserOne
newFileTwo := ConfigurationFile.UsersDirectory + PS + newUserTwo
newFileThree := ConfigurationFile.UsersDirectory + PS + newUserThree

errOne := AddNewUser(newUserOne)
errTwo := AddNewUser(newUserTwo)
errThree := AddNewUser(newUserThree)

assert.Nil(t, errOne)
assert.Nil(t, errTwo)
assert.Nil(t, errThree)

assert.Contains(t, newFileOne, newUserOne)
assert.Contains(t, newFileTwo, newUserTwo)
assert.Contains(t, newFileThree, newUserThree)

listOfUserResultPaths := ListOfUserResultPaths()
assert.Contains(t, listOfUserResultPaths[0], "Dracula")
assert.Contains(t, listOfUserResultPaths[1], "Monkey")
assert.Contains(t, listOfUserResultPaths[2], "Werewolf")
assert.Len(t, listOfUserResultPaths, 3)

os.RemoveAll(ConfigurationFile.UsersDirectory)

}

The second one did not remove the dir

What did you expect to see?

I expected to see the directory removed or an error reporting why it did not

What did you see instead?

I saw the directory remain

@cfair-beckman
Copy link
Author

Damn it close it....I discovered my own dumbassedness later works perfectly.

@golang golang locked and limited conversation to collaborators Oct 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants