Skip to content

Use CollectionAssert in ListDirectory tests - #1166

Merged
WojciechNagorski merged 4 commits into
sshnet:developfrom
Rob-Hague:collectionassert
Nov 13, 2023
Merged

Use CollectionAssert in ListDirectory tests#1166
WojciechNagorski merged 4 commits into
sshnet:developfrom
Rob-Hague:collectionassert

Conversation

@Rob-Hague

Copy link
Copy Markdown
Collaborator

These tests were failing for me because the files were coming in in a different order

Plus, CollectionAssert.AreEquivalent gives a nice failure message

@WojciechNagorski

Copy link
Copy Markdown
Collaborator

Can you tell me in what order you got the results?
I don't have full knowledge about the project yet, but perhaps the problem is not checking, but a random order.

@Rob-Hague

Copy link
Copy Markdown
CollaboratorAuthor
 Create_directory_with_contents_and_list_it
Source: SftpClientTests.cs line 21
Duration: 172 ms
Message: Assert.AreEqual failed. Expected:</home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
>. Actual:</home/sshnet/sshnet-test/test-file.txt True False
/home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
>. 

Same for Create_directory_with_contents_and_list_it_async

I have not looked at the implementation, but I would not expect it to do any sorting - the user can sort the files how they like.

@WojciechNagorski

Copy link
Copy Markdown
Collaborator

It needs to be checked. I don't know if it shouldn't be deterministic.

@Rob-Hague

Copy link
Copy Markdown
CollaboratorAuthor

So the directory listing functionality is the sending of a SSH_FXP_READDIR packet. I do not see anything relating to sort order in the RFC and the library implementation is reading out the filenames as they are returned (into an array, and then a list).

privateIEnumerable<ISftpFile>InternalListDirectory(stringpath,Action<int>listCallback)

publicKeyValuePair<string,SftpFileAttributes>[]RequestReadDir(byte[]handle)

protectedoverridevoidLoadData()
{
base.LoadData();
Count=ReadUInt32();
Files=newKeyValuePair<string,SftpFileAttributes>[Count];
for(vari=0;i<Count;i++)
{
varfileName=ReadString(Encoding);
if(SupportsLongName(ProtocolVersion))
{
_=ReadString(Encoding);// skip longname
}
Files[i]=newKeyValuePair<string,SftpFileAttributes>(fileName,ReadAttributes());
}
}

It looks fine to me.

@Rob-HagueRob-Hague mentioned this pull request Sep 23, 2023
@Rob-Hague

Copy link
Copy Markdown
CollaboratorAuthor

Also seen in #1220

 Failed Create_directory_with_contents_and_list_it [128 ms]
Error Message:
Assert.AreEqual failed. Expected:</home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
>. Actual:</home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
/home/sshnet/sshnet-test/. False True
>. Stack Trace:
at Renci.SshNet.IntegrationTests.SftpClientTests.Create_directory_with_contents_and_list_it() in /home/appveyor/projects/ssh-net/test/Renci.SshNet.IntegrationTests/SftpClientTests.cs:line 48
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

Comment threadtest/Renci.SshNet.IntegrationTests/SftpClientTests.cs Outdated
Comment threadtest/Renci.SshNet.IntegrationTests/SftpClientTests.cs Outdated
@WojciechNagorski

Copy link
Copy Markdown
Collaborator

It is strange, but I've just got the same error ;)
image

@WojciechNagorski
WojciechNagorski merged commit 823bc1b into sshnet:developNov 13, 2023
@Rob-Hague
Rob-Hague deleted the collectionassert branch November 13, 2023 07:31
@WojciechNagorskiWojciechNagorski added this to the 2023.0.1 milestone Nov 16, 2023
@WojciechNagorskiWojciechNagorski mentioned this pull request Dec 29, 2023
@WojciechNagorski

Copy link
Copy Markdown
Collaborator

The 2023.0.1 version has been released to Nuget: https://www.nuget.org/packages/SSH.NET/2023.0.1

This was referenced Aug 12, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Rob-Hague@WojciechNagorski@drieseng