2018-03-21 20:43:21 +01:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
2017-10-24 01:02:28 +02:00
|
|
|
|
|
|
|
import * as assert from "assert";
|
2018-02-05 23:44:23 +01:00
|
|
|
import { Inputs, runtime } from "../../index";
|
2017-10-24 01:02:28 +02:00
|
|
|
import { asyncTest } from "../util";
|
|
|
|
|
2018-01-25 22:34:21 +01:00
|
|
|
const gstruct = require("google-protobuf/google/protobuf/struct_pb.js");
|
|
|
|
|
2017-10-24 01:02:28 +02:00
|
|
|
describe("runtime", () => {
|
|
|
|
describe("transferProperties", () => {
|
|
|
|
it("marshals basic properties correctly", asyncTest(async () => {
|
2018-02-05 23:44:23 +01:00
|
|
|
const inputs: Inputs = {
|
2017-10-24 01:02:28 +02:00
|
|
|
"aNum": 42,
|
|
|
|
"bStr": "a string",
|
|
|
|
"cUnd": undefined,
|
2018-01-25 22:34:21 +01:00
|
|
|
"dArr": Promise.resolve([ "x", 42, Promise.resolve(true), Promise.resolve(undefined) ]),
|
2018-05-02 00:05:42 +02:00
|
|
|
"id": "foo",
|
|
|
|
"urn": "bar",
|
2017-10-24 01:02:28 +02:00
|
|
|
};
|
|
|
|
// Serialize and then deserialize all the properties, checking that they round-trip as expected.
|
2018-01-25 22:34:21 +01:00
|
|
|
const transfer = gstruct.Struct.fromJavaScript(
|
|
|
|
await runtime.serializeProperties("test", inputs));
|
|
|
|
const result = runtime.deserializeProperties(transfer);
|
2017-10-24 01:02:28 +02:00
|
|
|
assert.equal(result.aNum, 42);
|
|
|
|
assert.equal(result.bStr, "a string");
|
|
|
|
assert.equal(result.cUnd, undefined);
|
|
|
|
assert.deepEqual(result.dArr, [ "x", 42, true, undefined ]);
|
2018-05-02 00:05:42 +02:00
|
|
|
assert.equal(result.id, "foo");
|
|
|
|
assert.equal(result.urn, "bar");
|
2017-10-24 01:02:28 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|