after(async () => { await pubSubClient.topic(topicName).delete(); console.log(`Topic ${topicName} deleted.`); // Cleans up the registry by removing all associations and deleting all devices. tools.run(`${cmd} unbindAllDevices ${registryName}`, cwd); tools.run(`${cmd} clearRegistry ${registryName}`, cwd); console.log('Deleted test registry.'); });
before(async () => { tools.run(installDeps, `${cwd}/../mqtt_example`); tools.checkCredentials(); // Create a topic to be used for testing. const [topic] = await pubSubClient.createTopic(topicName); console.log(`Topic ${topic.name} created.`); // Creates a registry to be used for tests. const createRegistryRequest = { parent: iotClient.locationPath(projectId, region), deviceRegistry: { id: registryName, eventNotificationConfigs: [ { pubsubTopicName: topic.name, }, ], }, }; await tools.runAsync(`${cmd} setupIotTopic ${topicName}`, cwd); await iotClient.createDeviceRegistry(createRegistryRequest); console.log(`Created registry: ${registryName}`); });
const path = require('path'); const {PubSub} = require('@google-cloud/pubsub'); const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); const deviceId = 'test-node-device'; const topicName = `nodejs-docs-samples-test-iot-${uuid.v4()}`; const registryName = `nodejs-test-registry-iot-${uuid.v4()}`; const helper = 'node ../manager/manager.js'; const cmd = `node cloudiot_http_example.js --registryId="${registryName}" --deviceId="${deviceId}" `; const cwd = path.join(__dirname, '..'); const installDeps = 'npm install'; assert.ok(tools.run(installDeps, `${cwd}/../manager`)); before(async () => { tools.checkCredentials(); const pubsub = new PubSub(); const [topic] = await pubsub.createTopic(topicName); console.log(`Topic ${topic.name} created.`); }); after(async () => { const pubsub = new PubSub(); const topic = pubsub.topic(topicName); await topic.delete(); console.log(`Topic ${topic.name} deleted.`); }); it('should receive configuration message', async () => {