Thanks for viewing my previous questions and replying :) I seem to keep asking questions I can't find any answers to. I appreciate your thoughtful responses
I have a test target in my Swift Package called SystemTests. It needs some credentials (API key and token for a few services) at runtime in order to run the tests. Does anyone have suggestions on how I can do this without committing this file to git or making the process of running tests tedious.
- Keeping the environment variable in the Xcode scheme means the API key is stored in
xcschemexml file, and would be difficult to keep out of git. This is accessible throughProcessInfo.processInfo.environment["PRIVATE_API_KEY"]. Unfortunately system environment variables are not available. I'd love to be able to set the environment variables in e.g.~/.zshrc - Current/ flawed approach: I'm currently using a
Credentials.swift/Secrets.swiftfile which is added to.gitignoreand import it to the test file. I have anExample.Secrets.swiftfile which other developers can use. To avoid namespace collision between the global variables, I usestruct ExampleSecretsandstruct Secrets, for example:
struct ExampleSecrets {
let keyNameForServiceA = "put your key here"
let accessTokenForServiceB = "put your access token here"
}
Users need to rename ExampleSecrets to Secrets before it would compile.
The disadvantage of this is I can't share this Secrets file between targets/ test targets, because the Swift compiler will detect this. I can use a symlink to hack it together.