s/apparmor: use os.WriteFile in apparmor_test.go - #17008
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17008 +/- ##
==========================================
+ Coverage 79.06% 79.11% +0.05%
==========================================
Files 1375 1364 -11
Lines 191085 190918 -167
Branches 2465 2465
==========================================
- Hits 151075 151051 -24
+ Misses 30917 30779 -138
+ Partials 9093 9088 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Tue May 5 20:00:15 UTC 2026 Failures:Skipped tests from snapd-testing-skipIf you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list (without variants) of the below tests you wish to run (unskip plus test list must be valid yaml)
|
olivercalder
left a comment
There was a problem hiding this comment.
Thanks, these changes look good! Running a quick rg, I see several other places in the codebase where os.OpenFile, write, then close is used. Sometimes it's for good reason, like appending or writing at a particular offset, but I think there are other cases where we could replace it with os.WriteFile. This would probably be a good task to practice throwing a cheap and/or local LLM at, see what it can find.
|
Thanks! I noticed that too but I thought we wanted to limit it to just the package. Definitely the most LLM friendly task. |
2c460ad to
858b2ef
Compare
olivercalder
left a comment
There was a problem hiding this comment.
Looks good! I went rging for some more potential cases:
snap/squashfs/delta_test.go
721: f, err := os.OpenFile(deltaPath, os.O_APPEND|os.O_WRONLY, 0644)
722- c.Assert(err, IsNil)
723- _, err = f.Write(expectedData)
724- f.Close()
725- c.Assert(err, IsNil)
726-
--
829: f, err := os.OpenFile(deltaPath, os.O_RDWR, 0644)
830- c.Assert(err, IsNil)
831- _, err = f.WriteAt([]byte{0x63, 0x00}, 6) // 0x0063 = 99
832- f.Close()
833- c.Assert(err, IsNil)
834-
osutil/syncdir_test.go
399: file, err := os.OpenFile(testPath, os.O_RDWR, 0)
400- c.Assert(err, IsNil)
401- defer file.Close()
### mayyybe this one, not sure ###
sandbox/cgroup/freezer.go
181: f, err := os.OpenFile(where, os.O_WRONLY|os.O_TRUNC, 0644)
182- if err != nil {
183- return err
184- }
185- _, errW := f.Write(data)
186- errC := f.Close()
|
I found these as well when searching but none of them can be updated.
|
|
When I used 'rg' I noticed there are a few additional cases, not sure if they would be candidates or not.
These two are tagged RDWR but it seems its just the nil check
The rg expression I used to check is: This surfaces a lot more cases than I've stated, but some are clearly not good candidates. |
Rnfudge02
left a comment
There was a problem hiding this comment.
This looks a lot better than the existing syntax, a few other potential cases, but besides that this is looking good!
|
I took a look at these cases and they all do more than just writing with the |
Replace several separate
os.OpenFile,c.Check(err, IsNil),c.Check(file.Close(), IsNil)calls with a singleos.WriteFilecall.Pointed out in #15624 (comment)
Tracked with: SNAPDENG-35228