def RegisterResource(self, request, context): type_ = request.type name = request.name props = rpc.deserialize_resource_props(request.object) deps = request.dependencies outs = {} if type_ != "pulumi:pulumi:Stack": outs = self.langhost_test.register_resource( context, self.dryrun, type_, name, props, deps) if outs.get("urn"): urn = outs["urn"] self.registrations[urn] = { "type": type_, "name": name, "props": props } self.reg_count += 1 if outs.has_key("object"): obj_proto = rpc.serialize_resource_props(outs["object"]) else: obj_proto = None return proto.RegisterResourceResponse(urn=outs.get("urn"), id=outs.get("id"), object=obj_proto)
def test_empty(self): """ Tests that we serialize the empty Struct correctly. """ struct = rpc.serialize_resource_props({}) self.assertTrue(isinstance(struct, struct_pb2.Struct)) self.assertEqual(0, len(struct))
def test_file_asset(self): """ Tests that we serialize file assets correctly. """ struct = rpc.serialize_resource_props({"asset": FileAsset("file.txt")}) asset = struct["asset"] self.assertEqual(rpc._special_asset_sig, asset[rpc._special_sig_key]) self.assertEqual("file.txt", asset["path"])
def test_remote_asset(self): """ Tests that we serialize remote assets correctly. """ struct = rpc.serialize_resource_props( {"asset": RemoteAsset("https://pulumi.io")}) asset = struct["asset"] self.assertEqual(rpc._special_asset_sig, asset[rpc._special_sig_key]) self.assertEqual("https://pulumi.io", asset["uri"])
def test_string_asset(self): """ Tests that we serialize string assets correctly. """ struct = rpc.serialize_resource_props( {"asset": StringAsset("how do i python")}) asset = struct["asset"] self.assertEqual(rpc._special_asset_sig, asset[rpc._special_sig_key]) self.assertEqual("how do i python", asset["text"])
def test_unknown(self): """ Tests that we serialize instances of the Unknown class to the unknown GUID. """ struct = rpc.serialize_resource_props({"unknown_prop": Unknown()}) # pylint: disable=unsubscriptable-object unknown = struct["unknown_prop"] self.assertEqual(rpc.UNKNOWN, unknown)
def test_custom_resource(self): """ Tests that the class registered by `register_custom_resource_type` is serialized by serializing its ID field. """ struct = rpc.serialize_resource_props({"fake": FakeCustomResource(42)}) self.assertTrue(isinstance(struct, struct_pb2.Struct)) # pylint: disable=unsubscriptable-object serialized_resource = struct["fake"] self.assertEqual(42, serialized_resource)
def test_dict_of_lists(self): """ Tests that we serialize a struct containing a list correctly. """ struct = rpc.serialize_resource_props({"foo": [1, "2", True]}) self.assertTrue(isinstance(struct, struct_pb2.Struct)) # pylint: disable=unsubscriptable-object proto_list = struct["foo"] self.assertTrue(isinstance(proto_list, struct_pb2.ListValue)) self.assertEqual(1, proto_list[0]) self.assertEqual("2", proto_list[1]) self.assertEqual(True, proto_list[2])
def ReadResource(self, request, context): type_ = request.type name = request.name id_ = request.id parent = request.parent state = rpc.deserialize_resource_props(request.properties) outs = self.langhost_test.read_resource(context, type_, name, id_, parent, state) if outs.has_key("properties"): props_proto = rpc.serialize_resource_props(outs["properties"]) else: props_proto = None return proto.ReadResourceResponse(urn=outs.get("urn"), properties=props_proto)