2018-05-22 19:43:36 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2017-10-23 23:02:28 +00:00
|
|
|
|
|
|
|
import * as assert from "assert";
|
2018-02-05 22:44:23 +00:00
|
|
|
import { Inputs, runtime } from "../../index";
|
2017-10-23 23:02:28 +00:00
|
|
|
import { asyncTest } from "../util";
|
|
|
|
|
2018-01-25 21:34:21 +00:00
|
|
|
const gstruct = require("google-protobuf/google/protobuf/struct_pb.js");
|
|
|
|
|
2017-10-23 23:02:28 +00:00
|
|
|
describe("runtime", () => {
|
|
|
|
describe("transferProperties", () => {
|
|
|
|
it("marshals basic properties correctly", asyncTest(async () => {
|
2018-02-05 22:44:23 +00:00
|
|
|
const inputs: Inputs = {
|
2017-10-23 23:02:28 +00:00
|
|
|
"aNum": 42,
|
|
|
|
"bStr": "a string",
|
|
|
|
"cUnd": undefined,
|
2018-01-25 21:34:21 +00:00
|
|
|
"dArr": Promise.resolve([ "x", 42, Promise.resolve(true), Promise.resolve(undefined) ]),
|
2018-05-01 22:05:42 +00:00
|
|
|
"id": "foo",
|
|
|
|
"urn": "bar",
|
2017-10-23 23:02:28 +00:00
|
|
|
};
|
|
|
|
// Serialize and then deserialize all the properties, checking that they round-trip as expected.
|
2018-01-25 21:34:21 +00:00
|
|
|
const transfer = gstruct.Struct.fromJavaScript(
|
|
|
|
await runtime.serializeProperties("test", inputs));
|
|
|
|
const result = runtime.deserializeProperties(transfer);
|
2017-10-23 23:02:28 +00:00
|
|
|
assert.equal(result.aNum, 42);
|
|
|
|
assert.equal(result.bStr, "a string");
|
|
|
|
assert.equal(result.cUnd, undefined);
|
2018-05-23 21:47:40 +00:00
|
|
|
assert.deepEqual(result.dArr, [ "x", 42, true, null ]);
|
2018-05-01 22:05:42 +00:00
|
|
|
assert.equal(result.id, "foo");
|
|
|
|
assert.equal(result.urn, "bar");
|
2017-10-23 23:02:28 +00:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|