Skip to content

Commit

Permalink
Fix evaluation of env value
Browse files Browse the repository at this point in the history
If the value is dynamically obtained from an environment variable, an empty string
is set for the non-existing variable. This change prevents writing the artifacts
to an invalid / prohibited location.
  • Loading branch information
smidf committed Aug 20, 2023
1 parent dc46eeb commit b2a29e0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,13 @@ public func verifySnapshot<Value, Format>(
return nil
}

let artifactsUrl = URL(
fileURLWithPath: ProcessInfo.processInfo.environment["SNAPSHOT_ARTIFACTS"] ?? NSTemporaryDirectory(), isDirectory: true
)
let artifactsDirectory: String
if let value = ProcessInfo.processInfo.environment["SNAPSHOT_ARTIFACTS"], !value.isEmpty {
artifactsDirectory = value
} else {
artifactsDirectory = NSTemporaryDirectory()
}
let artifactsUrl = URL(fileURLWithPath: artifactsDirectory, isDirectory: true)
let artifactsSubUrl = artifactsUrl.appendingPathComponent(fileName)
try fileManager.createDirectory(at: artifactsSubUrl, withIntermediateDirectories: true)
let failedSnapshotFileUrl = artifactsSubUrl.appendingPathComponent(snapshotFileUrl.lastPathComponent)
Expand Down

0 comments on commit b2a29e0

Please sign in to comment.