Skip to content

Commit a14e834

Browse files
committed
printing entire log entry
1 parent 2a63369 commit a14e834

3 files changed

Lines changed: 50 additions & 10 deletions

File tree

src/services/resource-publisher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ export async function publishResource(
196196
if (val !== null) cleanProps[key] = val;
197197
}
198198
cleanProps.sourceApiId = `/subscriptions/${context.subscriptionId}/resourceGroups/${context.resourceGroup}/providers/Microsoft.ApiManagement/service/${context.serviceName}/apis/${baseApiName}`;
199+
// Preserve source current-revision intent. APIM can implicitly promote a
200+
// created revision to current if isCurrent is omitted; default to false
201+
// unless the extracted artifact explicitly set it.
202+
if (!Object.hasOwn(cleanProps, 'isCurrent')) {
203+
cleanProps.isCurrent = false;
204+
}
199205
json = { ...json, properties: cleanProps };
200206
}
201207
}

tests/integration/all-resource-types/Compare-ApimInstance.ps1

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,23 +378,15 @@ function Compare-NormalizedResources {
378378
}
379379
}
380380
else {
381-
$svLen = if ($null -ne $svJson) { $svJson.Length } else { 0 }
382-
$tvLen = if ($null -ne $tvJson) { $tvJson.Length } else { 0 }
383-
$svShort = if ($svLen -gt 120) { $svJson.Substring(0, 117) + '...' } else { $svJson }
384-
$tvShort = if ($tvLen -gt 120) { $tvJson.Substring(0, 117) + '...' } else { $tvJson }
385-
$diffs.Add(" DIFF at $currentPath`n source: $svShort`n target: $tvShort")
381+
$diffs.Add(" DIFF at $currentPath`n source: $svJson`n target: $tvJson")
386382
}
387383
}
388384
}
389385

390386
# Fallback: if JSON differs but no key-level diffs found, report the full diff
391387
if ($diffs.Count -eq 0) {
392388
$pathPrefix = if ($Path) { "${Path}: " } else { '' }
393-
$srcLen = if ($null -ne $sourceJson) { $sourceJson.Length } else { 0 }
394-
$tgtLen = if ($null -ne $targetJson) { $targetJson.Length } else { 0 }
395-
$srcShort = if ($srcLen -gt 200) { $sourceJson.Substring(0, 197) + '...' } else { $sourceJson }
396-
$tgtShort = if ($tgtLen -gt 200) { $targetJson.Substring(0, 197) + '...' } else { $targetJson }
397-
$diffs.Add(" ${pathPrefix}JSON differs`n source: $srcShort`n target: $tgtShort")
389+
$diffs.Add(" ${pathPrefix}JSON differs`n source: $sourceJson`n target: $targetJson")
398390
}
399391

400392
return ,$diffs

tests/unit/services/resource-publisher.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,48 @@ describe('resource-publisher', () => {
825825
`/subscriptions/${testContext.subscriptionId}/resourceGroups/${testContext.resourceGroup}/providers/Microsoft.ApiManagement/service/${testContext.serviceName}/apis/orders-api`;
826826
expect(props.sourceApiId).toBe(expectedSourceApiId);
827827
});
828+
829+
it('defaults revision isCurrent to false when missing', async () => {
830+
const client = createMockClient();
831+
const store = createMockStore();
832+
store.readResource.mockResolvedValue({
833+
name: 'orders-api;rev=2',
834+
properties: { path: '/orders' },
835+
});
836+
837+
const descriptor: ResourceDescriptor = {
838+
type: ResourceType.Api,
839+
nameParts: ['orders-api;rev=2'],
840+
};
841+
842+
await publishResource(client, store, testContext, descriptor, testConfig);
843+
844+
const putCall = client.putResource.mock.calls[0];
845+
const putJson = putCall[2] as Record<string, unknown>;
846+
const props = putJson.properties as Record<string, unknown>;
847+
expect(props).toHaveProperty('isCurrent', false);
848+
});
849+
850+
it('preserves revision isCurrent when explicitly provided', async () => {
851+
const client = createMockClient();
852+
const store = createMockStore();
853+
store.readResource.mockResolvedValue({
854+
name: 'orders-api;rev=2',
855+
properties: { path: '/orders', isCurrent: true },
856+
});
857+
858+
const descriptor: ResourceDescriptor = {
859+
type: ResourceType.Api,
860+
nameParts: ['orders-api;rev=2'],
861+
};
862+
863+
await publishResource(client, store, testContext, descriptor, testConfig);
864+
865+
const putCall = client.putResource.mock.calls[0];
866+
const putJson = putCall[2] as Record<string, unknown>;
867+
const props = putJson.properties as Record<string, unknown>;
868+
expect(props).toHaveProperty('isCurrent', true);
869+
});
828870
});
829871
});
830872

0 commit comments

Comments
 (0)