Skip to content

Add private Net::LDAP::Connection#write_request #116

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

Merged
merged 10 commits into from
Oct 16, 2014

Conversation

jch
Copy link
Member

@jch jch commented Oct 6, 2014

This new method accomplishes two things:

  • DRY up existing calls to #write
  • provide an entry point for test mocking what goes out on the wire

While working on #115, I noticed it was difficult to make assertions about what was being written out on the socket because those values were already BER encoded. By adding #write_request, it allows us to write assertions like the following:

# edited for typo
def test_some_operation
  mock = Minitest::Mock.new
  mock.expect(:write, true, [[1.to_ber, "some_operation's data"].to_ber_sequence])
  conn = Net::LDAP::Connection.new(:socket => mock)
  conn.some_operation(...)
end

It's possible to go even more general, but this refactoring is small and does what I want. I also introduced Minitest::Mock here. I saw that the project also has flexmock as a dependency, but proposed it with minitest in case that's the direction we want to move towards. If it's preferred, I can also figure out how to achieve the same mocking with flexmock.

cc @mtodd @schaary

Jerry Cheung added 6 commits October 6, 2014 14:55
allows us to mock out the actual connection for testing
higher level abstraction to make testing easier and to DRY up existing
socket IO
with #write_request
@mtodd
Copy link
Member

mtodd commented Oct 6, 2014

@jch do you think it might make sense to bake the write_request logic into the write method instead of adding another layer of logic? Don't want to overburden Net::LDAP::Connection#write but it's super slim right now, and if every call to write is wrapped in write_request, then it might make sense to inline this method.

@@ -10,7 +10,7 @@ def initialize(server)
@instrumentation_service = server[:instrumentation_service]

begin
@conn = TCPSocket.new(server[:host], server[:port])
@conn = server[:socket] || TCPSocket.new(server[:host], server[:port])
Copy link
Member

Choose a reason for hiding this comment

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

👌

@mtodd
Copy link
Member

mtodd commented Oct 6, 2014

No problems with using minitest/mock in general. Not a huge fan of adding more inconsistency, but if we're all 👍 to moving towards minitest and getting rid of flexmock (which I think we're all in agreement on), works for me.

@jch
Copy link
Member Author

jch commented Oct 6, 2014

do you think it might make sense to bake the write_request logic into the write method instead of adding another layer of logic?

Works for me. I started with #write_request because I wasn't sure if there were other callers for this interface, but that's unlikely seeing how it's private. It also doesn't affect existing behavior, so I don't see a problem there either.

not adding another method call. Since it's a private method, not giving any
deprecation warning.
@jch
Copy link
Member Author

jch commented Oct 7, 2014

@schaary @mtodd ready for more 👀

@mtodd
Copy link
Member

mtodd commented Oct 8, 2014

@jch 👍 diff looks good. Wishing we had integration tests right now. Would like to verify this against a directory service (AD or OpenLDAP) to be safe. Can do this later this week if you don't get a chance.

@jch
Copy link
Member Author

jch commented Oct 8, 2014

👍 I'll hold off merging until we have some basic integration tests then.

@mtodd mtodd self-assigned this Oct 12, 2014
@mtodd
Copy link
Member

mtodd commented Oct 12, 2014

Assigned myself since you're blocked on integration testing to move forward on this.

@mtodd
Copy link
Member

mtodd commented Oct 15, 2014

@jch added basic integration tests in #129, want me to merge them in and add integration tests for this? Or want to tackle integration tests?

Jerry Cheung added 2 commits October 15, 2014 20:36
since we're not moving away from flexmock just yet, I updated my tests to use
flexmock to be consistent. cc @mtodd
@jch
Copy link
Member Author

jch commented Oct 16, 2014

@mtodd what integrations tests do you have in mind?

Seeing how #write is internal and private, I think the unit tests may suffice.

end

def test_write_increments_msgid
mock = Minitest::Mock.new
Copy link
Member

Choose a reason for hiding this comment

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

@jch looks like this mock was missed.

@mtodd mtodd assigned jch and unassigned mtodd Oct 16, 2014
@mtodd
Copy link
Member

mtodd commented Oct 16, 2014

@jch technically, all operations go through write so the existing integration tests technically cover this change sufficiently; I was thinking it would be a good opportunity to add another integration test to expand overall coverage. For instance, we're missing basic integration tests on almost all of the operations touched here (all except for bind and search). I wouldn't block this PR on 'em, FWIW.

@jch
Copy link
Member Author

jch commented Oct 16, 2014

@mtodd gotcha. 👍 for adding more integration tests for all the public methods on Net::LDAP, but agree that we can do that in a separate PR. I'll fix up the CI issue and get this merged.

jch added a commit that referenced this pull request Oct 16, 2014
Add private Net::LDAP::Connection#write_request
@jch jch merged commit ed84f2b into ruby-ldap:master Oct 16, 2014
@jch jch deleted the connection-write-request branch October 16, 2014 18:09
astratto pushed a commit to astratto/ruby-net-ldap that referenced this pull request Dec 18, 2015
Add private Net::LDAP::Connection#write_request
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