|
| 1 | +import * as assert from "assert"; |
| 2 | +import * as pulumi from "@pulumi/pulumi"; |
| 3 | +import "mocha"; |
| 4 | +import { exampleNetworkAreaRoute, networkAreaId, networkAreaRouteId, networkAreaRouteLabelKey, networkAreaRouteLabelValue, networkAreaRouteNextHop, networkAreaRouteOrganizationId, networkAreaRoutePrefix } from "./index"; |
| 5 | + |
| 6 | +pulumi.runtime.setMocks({ |
| 7 | + newResource: function(args: pulumi.runtime.MockResourceArgs): {id: string, state: any} { |
| 8 | + return { |
| 9 | + id: args.inputs.name + "_id", |
| 10 | + state: args.inputs, |
| 11 | + }; |
| 12 | + }, |
| 13 | + call: function(args: pulumi.runtime.MockCallArgs) { |
| 14 | + // We check the token to identify which data source is being called. |
| 15 | + if (args.token === "stackit:index/getNetworkAreaRoute:getNetworkAreaRoute") { |
| 16 | + // Check if the input parameters were passed correctly |
| 17 | + if (args.inputs.organizationId !== networkAreaRouteOrganizationId || args.inputs.networkAreaId !== networkAreaId || args.inputs.networkAreaRouteId !== networkAreaRouteId) { |
| 18 | + throw new Error("getNetworkAreaRoute call received incorrect input parameters."); |
| 19 | + } |
| 20 | + // Return the complete object |
| 21 | + return { ...exampleNetworkAreaRoute, ...args.inputs }; |
| 22 | + } |
| 23 | + return args.inputs; |
| 24 | + }, |
| 25 | +}, |
| 26 | + "project", |
| 27 | + "stack", |
| 28 | + false, // Sets the flag `dryRun`, which indicates if pulumi is running in preview mode. |
| 29 | +); |
| 30 | + |
| 31 | +describe("exampleNetworkAreaRoute", () => { |
| 32 | + let infra: typeof import("./index"); |
| 33 | + |
| 34 | + before(async function() { |
| 35 | + // It's important to import the program _after_ the mocks are defined. |
| 36 | + infra = await import("./index"); |
| 37 | + }) |
| 38 | + |
| 39 | + it("networkAreaRoute must have a organization id", function(done) { |
| 40 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => { |
| 41 | + if (!exampleNetworkAreaRoute?.organizationId) { |
| 42 | + done(new Error(`Missing organization tag on exampleNetworkAreaRoute ${urn}`)); |
| 43 | + } else { |
| 44 | + done(); |
| 45 | + } |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it("networkAreaRoute must have a areaId", function(done) { |
| 50 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => { |
| 51 | + if (!exampleNetworkAreaRoute?.networkAreaId) { |
| 52 | + done(new Error(`Missing a areaId tag on exampleNetworkAreaRoute ${urn}`)); |
| 53 | + } else { |
| 54 | + done(); |
| 55 | + } |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + it("networkAreaRoute must have a prefix", function(done) { |
| 60 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => { |
| 61 | + if (!exampleNetworkAreaRoute?.prefix) { |
| 62 | + done(new Error(`Missing a prefix tag on exampleNetworkAreaRoute ${urn}`)); |
| 63 | + } else { |
| 64 | + done(); |
| 65 | + } |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it("networkAreaRoute must have a nextHop", function(done) { |
| 70 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute]).apply(([urn, exampleNetworkAreaRoute]) => { |
| 71 | + if (!exampleNetworkAreaRoute?.nextHop) { |
| 72 | + done(new Error(`Missing a nextHop tag on exampleNetworkAreaRoute ${urn}`)); |
| 73 | + } else { |
| 74 | + done(); |
| 75 | + } |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + it("check if organization id was correctly set", function(done) { |
| 80 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.organizationId]).apply(([urn, organizationId]) => { |
| 81 | + if (organizationId === networkAreaRouteOrganizationId) { |
| 82 | + done(); |
| 83 | + } else { |
| 84 | + done(new Error(`Provided organization id ${organizationId} was not set correctly on exampleNetworkAreaRoute ${urn}`)); |
| 85 | + } |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it("check if areaId was correctly set", function(done) { |
| 90 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.networkAreaId]).apply(([urn, areaId]) => { |
| 91 | + if (areaId === networkAreaId) { |
| 92 | + done(); |
| 93 | + } else { |
| 94 | + done(new Error(`Provided areaId ${areaId} was not set correctly on exampleNetworkAreaRoute ${urn}`)); |
| 95 | + } |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + it("check if prefix was correctly set", function(done) { |
| 100 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.prefix]).apply(([urn, prefix]) => { |
| 101 | + if (prefix === networkAreaRoutePrefix) { |
| 102 | + done(); |
| 103 | + } else { |
| 104 | + done(new Error(`Provided prefix ${prefix} was not set correctly on exampleNetworkAreaRoute ${urn}`)); |
| 105 | + } |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + it("check if nextHop was correctly set", function(done) { |
| 110 | + pulumi.all([infra.exampleNetworkAreaRoute.urn, infra.exampleNetworkAreaRoute.nextHop]).apply(([urn, nextHop]) => { |
| 111 | + if (nextHop === networkAreaRouteNextHop) { |
| 112 | + done(); |
| 113 | + } else { |
| 114 | + done(new Error(`Provided nextHop ${nextHop} was not set correctly on exampleNetworkAreaRoute ${urn}`)); |
| 115 | + } |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + it("check if the 'labels' map contains the correct key and value", function(done) { |
| 120 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.labels]).apply(([urn, labels]) => { |
| 121 | + const actualValue = labels ? labels[networkAreaRouteLabelKey] : undefined; |
| 122 | + if (actualValue === networkAreaRouteLabelValue) { |
| 123 | + done(); |
| 124 | + } else { |
| 125 | + done(new Error(`Label '${networkAreaRouteLabelKey}' was not set correctly. Actual: ${actualValue}, Expected: ${networkAreaRouteLabelValue} on datasource ${urn}`)); |
| 126 | + } |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | +}); |
| 131 | + |
| 132 | +// datasource |
| 133 | +describe("networkAreaRoute datasource test", () => { |
| 134 | + let infra: typeof import("./index"); |
| 135 | + |
| 136 | + // It's important to import the program _after_ the mocks are defined. |
| 137 | + before(async function() { |
| 138 | + infra = await import("./index"); |
| 139 | + }) |
| 140 | + |
| 141 | + it("networkAreaRoute must have a organization id", function(done) { |
| 142 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => { |
| 143 | + if (!networkAreaRouteDatasource?.organizationId) { |
| 144 | + done(new Error(`Missing organization tag on networkAreaRouteDatasource ${urn}`)); |
| 145 | + } else { |
| 146 | + done(); |
| 147 | + } |
| 148 | + }); |
| 149 | + }); |
| 150 | + |
| 151 | + it("networkAreaRoute must have a areaId", function(done) { |
| 152 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => { |
| 153 | + if (!networkAreaRouteDatasource?.networkAreaId) { |
| 154 | + done(new Error(`Missing a areaId tag on networkAreaRouteDatasource ${urn}`)); |
| 155 | + } else { |
| 156 | + done(); |
| 157 | + } |
| 158 | + }); |
| 159 | + }); |
| 160 | + |
| 161 | + it("check if networkAreaRouteId was correctly set", function(done) { |
| 162 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.networkAreaRouteId]).apply(([urn, networkAreaRouteId]) => { |
| 163 | + if (networkAreaRouteId === infra.networkAreaRouteId) { |
| 164 | + done(); |
| 165 | + } else { |
| 166 | + done(new Error(`Provided networkAreaRouteId ${networkAreaRouteId} was not set correctly on networkAreaRouteDatasource ${urn}`)); |
| 167 | + } |
| 168 | + }); |
| 169 | + }); |
| 170 | + |
| 171 | + it("networkAreaRoute must have a prefix", function(done) { |
| 172 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => { |
| 173 | + if (!networkAreaRouteDatasource?.prefix) { |
| 174 | + done(new Error(`Missing a prefix tag on networkAreaRouteDatasource ${urn}`)); |
| 175 | + } else { |
| 176 | + done(); |
| 177 | + } |
| 178 | + }); |
| 179 | + }); |
| 180 | + |
| 181 | + it("networkAreaRoute must have a nextHop", function(done) { |
| 182 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource]).apply(([urn, networkAreaRouteDatasource]) => { |
| 183 | + if (!networkAreaRouteDatasource?.nextHop) { |
| 184 | + done(new Error(`Missing a nextHop tag on networkAreaRouteDatasource ${urn}`)); |
| 185 | + } else { |
| 186 | + done(); |
| 187 | + } |
| 188 | + }); |
| 189 | + }); |
| 190 | + |
| 191 | + it("check if organization id was correctly set", function(done) { |
| 192 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.organizationId]).apply(([urn, organizationId]) => { |
| 193 | + if (organizationId === networkAreaRouteOrganizationId) { |
| 194 | + done(); |
| 195 | + } else { |
| 196 | + done(new Error(`Provided organization id ${organizationId} was not set correctly on networkAreaRouteDatasource ${urn}`)); |
| 197 | + } |
| 198 | + }); |
| 199 | + }); |
| 200 | + |
| 201 | + it("check if areaId was correctly set", function(done) { |
| 202 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.networkAreaId]).apply(([urn, areaId]) => { |
| 203 | + if (areaId === networkAreaId) { |
| 204 | + done(); |
| 205 | + } else { |
| 206 | + done(new Error(`Provided areaId ${areaId} was not set correctly on networkAreaRouteDatasource ${urn}`)); |
| 207 | + } |
| 208 | + }); |
| 209 | + }); |
| 210 | + |
| 211 | + it("check if prefix was correctly set", function(done) { |
| 212 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.prefix]).apply(([urn, prefix]) => { |
| 213 | + if (prefix === networkAreaRoutePrefix) { |
| 214 | + done(); |
| 215 | + } else { |
| 216 | + done(new Error(`Provided prefix ${prefix} was not set correctly on networkAreaRouteDatasource ${urn}`)); |
| 217 | + } |
| 218 | + }); |
| 219 | + }); |
| 220 | + |
| 221 | + it("check if nextHop was correctly set", function(done) { |
| 222 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.nextHop]).apply(([urn, nextHop]) => { |
| 223 | + if (nextHop === networkAreaRouteNextHop) { |
| 224 | + done(); |
| 225 | + } else { |
| 226 | + done(new Error(`Provided nextHop ${nextHop} was not set correctly on networkAreaRouteDatasource ${urn}`)); |
| 227 | + } |
| 228 | + }); |
| 229 | + }); |
| 230 | + |
| 231 | + it("check if the 'labels' map contains the correct key and value", function(done) { |
| 232 | + pulumi.all([infra.networkAreaRouteDatasource, infra.networkAreaRouteDatasource.labels]).apply(([urn, labels]) => { |
| 233 | + const actualValue = labels ? labels[networkAreaRouteLabelKey] : undefined; |
| 234 | + if (actualValue === networkAreaRouteLabelValue) { |
| 235 | + done(); |
| 236 | + } else { |
| 237 | + done(new Error(`Label '${networkAreaRouteLabelKey}' was not set correctly. Actual: ${actualValue}, Expected: ${networkAreaRouteLabelValue} on datasource ${urn}`)); |
| 238 | + } |
| 239 | + }); |
| 240 | + }); |
| 241 | +}); |
0 commit comments