-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add axios to devDependencies and enhance pulsar-consumer tests
Added 'axios' to the devDependencies in the package.json file, enabling the use of this tool in development and testing environments. Additionally, made several improvements to the test coverage for the 'pulsar-consumer.js'. This includes better management of the Pulsar container and the addition of a new file: 'pulsar-container.js'.
- Loading branch information
Showing
5 changed files
with
100 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { GenericContainer, Wait } = require("testcontainers"); | ||
const axios = require('axios'); | ||
|
||
function createPulsarContainer(done, callback) { | ||
new GenericContainer("apachepulsar/pulsar:3.1.1") | ||
.withCommand(["bin/pulsar", "standalone"]) | ||
.withExposedPorts(6650, 8080) | ||
.withWaitStrategy(Wait.forHttp("/admin/v2/persistent/public/default", 8080)) | ||
.start() | ||
.then(function (container) { | ||
console.log("Pulsar container started"); | ||
callback(container); | ||
}).catch(function (error) { | ||
console.error(error) | ||
done(error); | ||
}); | ||
} | ||
|
||
function stopPulsarContainer(container, done) { | ||
container.stop() | ||
.then(function () { | ||
console.log("Pulsar container stopped"); | ||
done(); | ||
}).catch(function (error) { | ||
console.error(error) | ||
done(error); | ||
}); | ||
} | ||
|
||
function createTopic(container, topic, done, callback) { | ||
const serviceUrl = "http://localhost:" + container.getMappedPort(8080); | ||
axios.put(serviceUrl + '/admin/v2/persistent/public/default/' + topic, {}, { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(function (response) { | ||
console.log("Topic created", response.status); | ||
callback(); | ||
}).catch(function (error) { | ||
console.error(error) | ||
done(error); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
createPulsarContainer: createPulsarContainer, | ||
stopPulsarContainer: stopPulsarContainer, | ||
createTopic: createTopic | ||
} |