Skip to content

Commit

Permalink
export protocol, to make lesser-used symbols available; use only publ…
Browse files Browse the repository at this point in the history
…icly available imports in tests
  • Loading branch information
SillyFreak committed Nov 10, 2018
1 parent 1cdb7b7 commit 9ca757d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
3 changes: 3 additions & 0 deletions hedgehog/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './client/hedgehogClient';
export { Message, ack, io, analog, digital, motor, servo, process } from './protocol';

import * as protocol from './protocol';
export { protocol };
7 changes: 3 additions & 4 deletions test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import "@babel/polyfill";
import * as assert from 'assert';
import * as zmq from 'zeromq';

import { HedgehogClient, Message, ack, io, analog } from "../hedgehog";
import { RequestMsg, ReplyMsg } from '../hedgehog/protocol';
import { HedgehogClient, protocol, Message, ack, io, analog } from "../hedgehog";

describe('Client', () => {
let server = null;
Expand Down Expand Up @@ -33,13 +32,13 @@ describe('Client', () => {

for(let [expected, responses] of pairs) {
let [ident, delimiter, ...data] = await recv();
let requests = data.map(msg => RequestMsg.parse(msg));
let requests = data.map(msg => protocol.RequestMsg.parse(msg));

assert.deepEqual(requests, expected);

server.send([
ident, delimiter,
...responses.map(msg => Buffer.from(ReplyMsg.serialize(msg)))
...responses.map(msg => Buffer.from(protocol.ReplyMsg.serialize(msg)))
]);
}
}
Expand Down
81 changes: 40 additions & 41 deletions test/protocol.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import * as assert from 'assert';

import { hedgehog_pb, ack_pb, io_pb, motor_pb, servo_pb, process_pb,
subscription_pb } from '../hedgehog/protocol/proto';
import { Message, ack, io, analog, digital, motor, servo, process } from "../hedgehog";
import { RequestMsg, ReplyMsg, ContainerMessage} from '../hedgehog/protocol';
import { protocol, Message, ack, io, analog, digital, motor, servo, process } from "../hedgehog";
import { ProtoContainerMessage } from "../hedgehog/utils/protobuf";

describe('Protocol', () => {
function testMessage(msg: Message, wire: ProtoContainerMessage, container: ContainerMessage) {
function testMessage(msg: Message, wire: ProtoContainerMessage, container: protocol.ContainerMessage) {
let onWire = container.serialize(msg);
assert.deepEqual(onWire, wire.serializeBinary());
let received = container.parse(onWire);
Expand All @@ -33,7 +32,7 @@ describe('Protocol', () => {
});

let msg = new ack.Acknowledgement();
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -47,7 +46,7 @@ describe('Protocol', () => {
});

let msg = new io.Action(0, io.IOFlags.OUTPUT_ON);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});
});

Expand All @@ -60,7 +59,7 @@ describe('Protocol', () => {
});

let msg = new io.CommandRequest(0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `io.CommandSubscribe` successfully", () => {
Expand All @@ -76,7 +75,7 @@ describe('Protocol', () => {
});

let msg = new io.CommandSubscribe(0, sub);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `io.CommandReply` successfully", () => {
Expand All @@ -88,7 +87,7 @@ describe('Protocol', () => {
});

let msg = new io.CommandReply(0, io.IOFlags.OUTPUT_ON);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});

it("should translate `io.CommandUpdate` successfully", () => {
Expand All @@ -105,7 +104,7 @@ describe('Protocol', () => {
});

let msg = new io.CommandUpdate(0, io.IOFlags.OUTPUT_ON, sub);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -118,7 +117,7 @@ describe('Protocol', () => {
});

let msg = new analog.Request(0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `analog.Subscribe` successfully", () => {
Expand All @@ -134,7 +133,7 @@ describe('Protocol', () => {
});

let msg = new analog.Subscribe(0, sub);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `analog.Reply` successfully", () => {
Expand All @@ -146,7 +145,7 @@ describe('Protocol', () => {
});

let msg = new analog.Reply(0, 1000);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});

it("should translate `analog.Update` successfully", () => {
Expand All @@ -163,7 +162,7 @@ describe('Protocol', () => {
});

let msg = new analog.Update(0, 1000, sub);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -176,7 +175,7 @@ describe('Protocol', () => {
});

let msg = new digital.Request(0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `digital.Subscribe` successfully", () => {
Expand All @@ -192,7 +191,7 @@ describe('Protocol', () => {
});

let msg = new digital.Subscribe(0, sub);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `digital.Reply` successfully", () => {
Expand All @@ -204,7 +203,7 @@ describe('Protocol', () => {
});

let msg = new digital.Reply(0, true);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});

it("should translate `digital.Update` successfully", () => {
Expand All @@ -221,7 +220,7 @@ describe('Protocol', () => {
});

let msg = new digital.Update(0, true, sub);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -235,7 +234,7 @@ describe('Protocol', () => {
});

let msg = new motor.Action(0, motor.MotorState.POWER);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `motor.Action` with amount successfully", () => {
Expand All @@ -248,7 +247,7 @@ describe('Protocol', () => {
});

let msg = new motor.Action(0, motor.MotorState.POWER, 1000);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});
});

Expand All @@ -262,7 +261,7 @@ describe('Protocol', () => {
});

let msg = new motor.SetPositionAction(0, 0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});
});

Expand All @@ -275,7 +274,7 @@ describe('Protocol', () => {
});

let msg = new motor.CommandRequest(0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `motor.CommandSubscribe` successfully", () => {
Expand All @@ -291,7 +290,7 @@ describe('Protocol', () => {
});

let msg = new motor.CommandSubscribe(0, sub);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `motor.CommandReply` successfully", () => {
Expand All @@ -304,7 +303,7 @@ describe('Protocol', () => {
});

let msg = new motor.CommandReply(0, motor.MotorState.POWER, 1000);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});

it("should translate `motor.CommandUpdate` successfully", () => {
Expand All @@ -322,7 +321,7 @@ describe('Protocol', () => {
});

let msg = new motor.CommandUpdate(0, motor.MotorState.POWER, 1000, sub);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -335,7 +334,7 @@ describe('Protocol', () => {
});

let msg = new motor.StateRequest(0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `motor.StateSubscribe` successfully", () => {
Expand All @@ -351,7 +350,7 @@ describe('Protocol', () => {
});

let msg = new motor.StateSubscribe(0, sub);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `motor.StateReply` successfully", () => {
Expand All @@ -364,7 +363,7 @@ describe('Protocol', () => {
});

let msg = new motor.StateReply(0, 0, 0);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});

it("should translate `motor.StateUpdate` successfully", () => {
Expand All @@ -382,7 +381,7 @@ describe('Protocol', () => {
});

let msg = new motor.StateUpdate(0, 0, 0, sub);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -396,7 +395,7 @@ describe('Protocol', () => {
});

let msg = new servo.Action(0, false);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `servo.Action` with position successfully", () => {
Expand All @@ -409,7 +408,7 @@ describe('Protocol', () => {
});

let msg = new servo.Action(0, true, 1000);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});
});

Expand All @@ -422,7 +421,7 @@ describe('Protocol', () => {
});

let msg = new servo.CommandRequest(0);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `servo.CommandSubscribe` successfully", () => {
Expand All @@ -438,7 +437,7 @@ describe('Protocol', () => {
});

let msg = new servo.CommandSubscribe(0, sub);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `servo.CommandReply` successfully", () => {
Expand All @@ -450,7 +449,7 @@ describe('Protocol', () => {
});

let msg = new servo.CommandReply(0, false, undefined);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});

it("should translate `servo.CommandUpdate` successfully", () => {
Expand All @@ -467,7 +466,7 @@ describe('Protocol', () => {
});

let msg = new servo.CommandUpdate(0, false, undefined, sub);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -481,7 +480,7 @@ describe('Protocol', () => {
});

let msg = new process.ExecuteAction(["cat"], "/home/pi");
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});
});

Expand All @@ -494,7 +493,7 @@ describe('Protocol', () => {
});

let msg = new process.ExecuteReply(1234);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -508,7 +507,7 @@ describe('Protocol', () => {
});

let msg = new process.StreamAction(1234, process.ProcessFileno.STDIN);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `process.StreamAction` with empty chunk successfully", () => {
Expand All @@ -520,7 +519,7 @@ describe('Protocol', () => {
});

let msg = new process.StreamAction(1234, process.ProcessFileno.STDIN, Uint8Array.from('' as any));
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});

it("should translate `process.StreamUpdate` with nonempty chunk successfully", () => {
Expand All @@ -533,7 +532,7 @@ describe('Protocol', () => {
});

let msg = new process.StreamUpdate(1234, process.ProcessFileno.STDOUT, Uint8Array.from('\x00' as any));
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});

Expand All @@ -547,7 +546,7 @@ describe('Protocol', () => {
});

let msg = new process.SignalAction(1234, 9);
testMessage(msg, wire, RequestMsg);
testMessage(msg, wire, protocol.RequestMsg);
});
});

Expand All @@ -561,7 +560,7 @@ describe('Protocol', () => {
});

let msg = new process.ExitUpdate(1234, 0);
testMessage(msg, wire, ReplyMsg);
testMessage(msg, wire, protocol.ReplyMsg);
});
});
});

0 comments on commit 9ca757d

Please sign in to comment.