Advertisement
Guest User

Untitled

a guest
Apr 14th, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. import unittest
  2. import pulumi
  3.  
  4. class PulumiMocks(pulumi.runtime.Mocks):
  5.     def new_resource(self, type_, name, inputs, provider, id_):
  6.         return [name + "_id", inputs]
  7.  
  8.     def call(self, token, args, provider):
  9.         if token == "azure:core/getSubscription:getSubscription":
  10.             return {
  11.                 "id": "00000000-0000-0000-0000-000000000000",
  12.                 "display_name": "subscription",
  13.             }
  14.         elif token == "azure:compute/getSharedImageVersion:getSharedImageVersion":
  15.             return {
  16.                 "exclude_from_latest": False,
  17.             }
  18.         else:
  19.             return {}
  20.  
  21. pulumi.runtime.set_mocks(PulumiMocks())
  22.  
  23. # Now actually import the code that creates resources, and then test it.
  24. import vm
  25.  
  26. MODULES = [vm]
  27.  
  28.  
  29. class TestingMocks(unittest.TestCase):
  30.     def __init__(self, *args, **kwargs):
  31.         super(TestingMocks, self).__init__(*args, **kwargs)
  32.         self.resources = dict()
  33.  
  34.         def save(args):
  35.             return {args[i]: args[i + 1] for i in range(0, len(args), 2)}
  36.  
  37.         for module in MODULES:
  38.             for resource in module.__dict__.values():
  39.                 if hasattr(resource, "urn"):
  40.                     flatten = [s for sublst in resource.__dict__.items() for s in sublst]
  41.                     self.resources[resource.urn] = pulumi.Output.all(*flatten).apply(save)
  42.  
  43.     @pulumi.runtime.test
  44.     def test_show(self):
  45.         print("==================================================================")
  46.         print(self.resources)
  47.         print("==================================================================")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement