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
[JENKINS-48407] Re-enable test #3275
[JENKINS-48407] Re-enable test #3275
Conversation
The previous test assumed permissions would always be the same, when they actually depend on umask settings. This change creates a file *not* using the temporary API, gets its permissions then compares it to the ones obtained using AtomicFileWriter. Note: we now only check the given permissions, not the "non-given".
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 validated the test on my machine with a umask of 022 and 002. My only suggestion is that it might be better to directly assert that the expected and actual permissions are equal.
import static java.nio.file.attribute.PosixFilePermission.OTHERS_READ; | ||
import static java.nio.file.attribute.PosixFilePermission.OTHERS_WRITE; | ||
import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE; | ||
import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; | ||
import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; |
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.
nit: I think all of the static imports from java.nio.file.attribute.PosixFilePermission.*
are unused.
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.
Done
for (PosixFilePermission perm : notGivenPermissions) { | ||
assertFalse("should not be allowed: " + perm, posixFilePermissions.contains(perm)); | ||
for (PosixFilePermission perm : DEFAULT_GIVEN_PERMISSIONS) { | ||
assertTrue("missing expected permission: " + perm, posixFilePermissions.contains(perm)); |
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.
Maybe replace the loop with assertThat(posixFilePermissions, equalTo(DEFAULT_GIVEN_PERMISSIONS))
to catch any changes that add extra permissions as well? You would also get nicely formatted failures for free:
Expected: <[OWNER_READ, GROUP_READ, OTHERS_READ, OWNER_WRITE]>
but: was <[OWNER_READ, OTHERS_WRITE, GROUP_READ, OTHERS_READ, OWNER_WRITE]>
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.
Done.
Thanks @dwnusbaum !
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.
Hearty upvote!
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.
🐝 and @reviewbybees done
@Rule | ||
public TemporaryFolder tmp = new TemporaryFolder(); | ||
File af; | ||
AtomicFileWriter afw; | ||
String expectedContent = "hello world"; | ||
|
||
@BeforeClass | ||
public static void computePermissions() throws IOException { | ||
final File tempDir = com.google.common.io.Files.createTempDir(); |
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.
why are you introducing this - you have TemporaryFolder
which can create directories...
if (!isPosixSupported(newFile)) { | ||
return; | ||
} | ||
DEFAULT_GIVEN_PERMISSIONS = Files.getPosixFilePermissions(newFile.toPath()); |
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 file and directory are not deleted
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.
Not really a bug, granted the tmp directory could grow, but well it's not even production code. Using TemporaryFolder
instead, constantly forget about this one.
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.
@jtnord fixed in last commit.
Followup of #3274
The previous test assumed permissions would always be the same, when they actually depend on umask settings.
This change creates a file not using the temporary API, gets its permissions then compares it to the ones obtained using
AtomicFileWriter
.Note: we now only check the given permissions, not the "non-given".
See JENKINS-48407.
Proposed changelog entries
N/A: changes only under src/test.
* Use the
Internal:
prefix if the change has no user-visible impact (API, test frameworks, etc.)Desired reviewers
@reviewbybees esp. @daniel-beck