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

Add Client.Sync method #386

Merged
merged 1 commit into from
Oct 23, 2020
Merged

Add Client.Sync method #386

merged 1 commit into from
Oct 23, 2020

Conversation

greatroar
Copy link
Contributor

packet.go Show resolved Hide resolved
// XXX We can't distinguish an actual fsync not supported
// error from a typo in the extension name here.
t.Logf("Sync: %v", err)
assert.Equal(t, ErrSSHFxOpUnsupported, err.FxCode())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, there are two paths on this where this test can pass: either err == nil or err.(*StatusError).FxCode() == ErrSSHFxOpUnsupported. I’m kind of hesitant on having more than one way a test can pass. A test should be well-constructed enough to ensure that there is only one valid behavior, and thus only one codepath that should pass the test.

Is this running against our own server implementation, which is why we account that it might return “unsupported”? Then maybe we should write support for it, or at least a stub of a support somehow, just so that it is not met immediately with unsupported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is primarily so I don't have to write the server part. I only use the client. We could check whether the test is running against a real server and be stricter in that case; OpenSSH has had this extension since 2013.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would highly recommend against making the tests smarter than they need to be, like, checking to see if the server supports the feature or not, before running the test. You end up in a situation where the test is no longer clear, and “is this passing because it actually behaves as we expect it to, or because the server unexpected does not support the feature.”

I would recommend instead putting it in its own TestClientSync that will expect only the SSHFxOpUnsupported case, and explicitly document with comments that this test will need to be reworked once the internal server actually supports the function. (Which the implementer should come across, because the test should actually fail at that point.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced this by two integration tests, including one for an actual server. I do like to check whether the method actually works with OpenSSH :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great solution! Thanks for sticking through, sorry about the delays.

client_integration_test.go Outdated Show resolved Hide resolved
client_integration_test.go Outdated Show resolved Hide resolved

// Since Server does not support the fsync extension, we can only
// check that we get the right error.
require.NotNil(t, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, I didn’t check the usage of require and assert as closely as I should have. 🤦‍♀️

Sign up for free to 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.

2 participants