-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Identity] Different approach for testing the Arc feature, instead of mock-fs #15571
Conversation
sdk/identity/identity/test/internal/node/managedIdentityCredential.spec.ts
Outdated
Show resolved
Hide resolved
2201f8d
to
aa2ab54
Compare
@mikeharder @praveenkuttappan I un-did the changes to the pnpm-lock file, after what Mike said |
// Trigger Azure Arc behavior by setting environment variables | ||
|
||
process.env.IMDS_ENDPOINT = "https://endpoint"; | ||
process.env.IDENTITY_ENDPOINT = "https://endpoint"; | ||
|
||
const filePath = "path/to/file"; | ||
const filePath = join(tmpdir(), `${Date.now()}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this has two issues:
- The
filePath
could collide if another test usedDate.now()
and ran at the same time. - The file is not guaranteed to be deleted if an exception is thrown.
Here's my suggestion:
const fs = require('fs-extra');
const os = require('os');
const path = require('path');
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "test-"));
try {
const tempFile = path.join(tempDir, "test");
fs.writeFileSync(tempFile, "hello");
// Use tempFile
}
finally {
fs.rmdirSync(tempDir, { recursive: true });
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll take your suggestion, but I don’t see the point of the folder! I’ll push something that should be enough though, unless I’m missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this? e43377d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, one more improvement here: a11c1df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of the folder is Node provides an API for creating a guaranteed-unique temp folder (fs.mkdtemp()
) but not a guaranteed-unique temp file.
This code is still vulnerable to possible collisions, but if you think it's good enough for our test code then I won't block it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh I see your point! Thank you for pointing that out to me. I’ll follow your approach!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeharder I couldn’t use the recursive parameter because it wasn’t recognized by our typescript, so I deleted the file and then the directory: e82fe6a
Hello @sadasant! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
track2 modify operationalinsights readme.go.md (Azure#15571)
Recently we found an issue on our CI build for Node 16.3.0, which boiled down to one unit test specific to Identity: #15547
After some investigation, it is clear that Node 16.3.0 has some incompatibility with mock-fs: tschaub/mock-fs#332
In the mean time, to add this test again, we can simply create a file, point to it and delete it at the end. This should work in all versions of Node, and it means one less dev-dependency for us.