]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/nodejs/test/header.test.js
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / nodejs / test / header.test.js
CommitLineData
f67539c2
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20const TFramedTransport = require("../lib/thrift/framed_transport");
21const THeaderTransport = require("../lib/thrift/header_transport");
22const THeaderProtocol = require("../lib/thrift/header_protocol");
23const thrift = require("../lib/thrift");
24const fs = require("fs");
25const test = require("tape");
26const path = require("path");
27
28const headerPayload = fs.readFileSync(
29 path.join(__dirname, "test_header_payload")
30);
31
32const cases = {
33 "Should read headers from payload": function(assert) {
34 const transport = new TFramedTransport();
35 transport.inBuf = Buffer.from(headerPayload);
36
37 const headers = transport.readHeaders();
38 assert.equals(headers.Parent, "shoobar");
39 assert.equals(headers.Trace, "abcde");
40 assert.end();
41 },
42 "Should read headers when reading message begin": function(assert) {
43 const transport = new TFramedTransport();
44 transport.inBuf = Buffer.from(headerPayload);
45 const protocol = new THeaderProtocol(transport);
46 const result = protocol.readMessageBegin();
47
48 const headers = transport.getReadHeaders();
49 assert.equals(headers.Parent, "shoobar");
50 assert.equals(headers.Trace, "abcde");
51 assert.equals(result.fname, "add");
52 assert.equals(result.mtype, thrift.Thrift.MessageType.CALL);
53 assert.end();
54 },
55 "Should be able to write headers": function(assert) {
56 const writeTransport = new TFramedTransport();
57 writeTransport.setProtocolId(THeaderTransport.SubprotocolId.BINARY);
58 writeTransport.setWriteHeader("Hihihihi", "hohohoho");
59 writeTransport.setWriteHeader("boobooboo", "fooshoopoo");
60 writeTransport.setWriteHeader("a", "z");
61 writeTransport.writeHeaders();
62 const writeBuffer = writeTransport.outBuffers[0];
63
64 const readTransport = new TFramedTransport();
65 readTransport.inBuf = writeBuffer;
66 readTransport.readHeaders();
67
68 const headers = readTransport.getReadHeaders();
69 assert.equals(headers.Hihihihi, "hohohoho");
70 assert.equals(headers.boobooboo, "fooshoopoo");
71 assert.equals(headers.a, "z");
72 assert.end();
73 }
74};
75
76Object.keys(cases).forEach(function(caseName) {
77 test(caseName, cases[caseName]);
78});