From e2f68c8f4e7375c157f1e994fecff0084d52ef43 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Wed, 24 Nov 2021 21:41:34 +0100 Subject: [PATCH] Add unit tests for thinning creator plugin --- .../Thinning/ThinningCreatorPluginTests.swift | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Tests/XCRemoteCacheTests/Commands/Plugins/Thinning/ThinningCreatorPluginTests.swift b/Tests/XCRemoteCacheTests/Commands/Plugins/Thinning/ThinningCreatorPluginTests.swift index 6f49fea..4be637b 100644 --- a/Tests/XCRemoteCacheTests/Commands/Plugins/Thinning/ThinningCreatorPluginTests.swift +++ b/Tests/XCRemoteCacheTests/Commands/Plugins/Thinning/ThinningCreatorPluginTests.swift @@ -76,4 +76,62 @@ class ThinningCreatorPluginTests: FileXCTestCase { XCTAssertThrowsError(try plugin.extraMetaKeys(Self.sampleMeta)) } + + func testDefinesExtraMetaKeysForTargetsThatReusedArtifact() throws { + let otherTargetTempDir = targetTempDirRoot.appendingPathComponent("Other.build") + let marker = otherTargetTempDir.appendingPathComponent("rc.enabled") + let reusedArtifact = otherTargetTempDir + .appendingPathComponent("xccache") + .appendingPathComponent("123") + .appendingPathExtension("zip") + try fileManager.spt_createEmptyFile(marker) + try fileManager.spt_createEmptyFile(reusedArtifact) + + let extraKeys = try plugin.extraMetaKeys(Self.sampleMeta) + + XCTAssertEqual(extraKeys, ["thinning_Other": "123"]) + } + + func testFailsGeneratingExtraMetaKeysForTwoArtifactsInTargetTempDir() throws { + let otherTargetTempDir = targetTempDirRoot.appendingPathComponent("Other.build") + let marker = otherTargetTempDir.appendingPathComponent("rc.enabled") + let reusedArtifact1 = otherTargetTempDir + .appendingPathComponent("xccache") + .appendingPathComponent("001") + .appendingPathExtension("zip") + let reusedArtifact2 = otherTargetTempDir + .appendingPathComponent("xccache") + .appendingPathComponent("002") + .appendingPathExtension("zip") + try fileManager.spt_createEmptyFile(marker) + try fileManager.spt_createEmptyFile(reusedArtifact1) + try fileManager.spt_createEmptyFile(reusedArtifact2) + + XCTAssertThrowsError(try plugin.extraMetaKeys(Self.sampleMeta)) + } + + func testDefinesExtraMetaKeysForGeneratedAndReusedArtifact() throws { + let otherTargetTempDir = targetTempDirRoot.appendingPathComponent("Generated.build") + let generatedArtifact = otherTargetTempDir + .appendingPathComponent("xccache") + .appendingPathComponent("produced") + .appendingPathComponent("000") + .appendingPathExtension("zip") + try fileManager.spt_createEmptyFile(generatedArtifact) + let reusedTargetTempDir = targetTempDirRoot.appendingPathComponent("Reused.build") + let marker = reusedTargetTempDir.appendingPathComponent("rc.enabled") + let reusedArtifact = reusedTargetTempDir + .appendingPathComponent("xccache") + .appendingPathComponent("999") + .appendingPathExtension("zip") + try fileManager.spt_createEmptyFile(marker) + try fileManager.spt_createEmptyFile(reusedArtifact) + + let extraKeys = try plugin.extraMetaKeys(Self.sampleMeta) + + XCTAssertEqual(extraKeys, [ + "thinning_Generated": "000", + "thinning_Reused": "999" + ]) + } }