Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

fix: Add tests for .block promise API #170

Closed
wants to merge 2 commits into from
Closed

fix: Add tests for .block promise API #170

wants to merge 2 commits into from

Conversation

haadcode
Copy link
Contributor

This PR will add tests for the promise API of .block

I also added a test for callback block.rm() as it was missing

@haadcode
Copy link
Contributor Author

Needed for ipfs/js-ipfs#1085

Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

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

THanks for the tests @haadcode, solid!

They need to be changed to avoid using internals though, these tests are always tests against js-ipfs and js-ipfs-api

src/block.js Outdated
// Remove bitswap from IPFS so that block.get tries to fetch the block
// from the local repo (not from the network). This is to make sure we
// get the error (as expected) instead of waiting for a timeout.
ipfs._blockService._bitswap = null
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests can't use any internals otherwise it will fail with js-ipfs-api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh :/ I figured that was a a bit of a workaround. Any suggestions how to avoid the block.get() trying to get the block from bitswap thus causing it "never" to return? The idea here is to get block.get() to return an error (ie. "we don't have the block anymore").

Copy link
Contributor

Choose a reason for hiding this comment

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

You will just have to .skip that test until we have https:/ipfs/interface-ipfs-core/issues/58, unfortunately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. That's unfortunate. I'll update the commit and .skip it for now. Let's leave the tests there though, so that we have them ready for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Committed. I removed the line where bitswap was nulled, added .skip to both callback and promise tests for .rm() and added some notes in the code as to why.

Copy link
Contributor

@daviddias daviddias left a comment

Choose a reason for hiding this comment

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

Could you make sure that both of these run successfully against js-ipfs and js-ipfs-api? Thank you!

@haadcode
Copy link
Contributor Author

@diasdavid I believe these are running fine with both now after skipping the .rm() part. Did I miss something? Is there anything we need to change to get this merged?

@daviddias
Copy link
Contributor

Hi @haadcode, this PR needs a rebase :)

@daviddias
Copy link
Contributor

ping @haadcode

Add test for callback-based .rm()
Add test for all promise-based functions
@haadcode
Copy link
Contributor Author

haadcode commented Dec 9, 2017

Sorry this took a while, it's rebased now! 🚀

it('a buffer, using defaults', (done) => {
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blob = new Buffer('blorb')
describe('callback API', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@haadcode I believe you missed that there is no more separation between Callback API and Promise API and through your rebase you brought it back and duplicated some come.

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 did not notice that. Will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@diasdavid I started to look into this but I'm little confused. Can you help here to elaborate what you mean with "no more separation between Callback and Promise API"? We still have them both, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

We still have both, but we don't duplicate the tests anymore :)

@daviddias
Copy link
Contributor

Closing this one.

@daviddias daviddias closed this Mar 16, 2018
@ghost ghost removed the in progress label Mar 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants