11 Commits

Author SHA1 Message Date
Miguel Pires
79c5ac14b2 many: remove usages of deprecated io/ioutil package (#13768)
* many: remove usages of deprecated io/ioutil package

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* .golangci.yml: remove errcheck ignore rule for io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* run-checks: prevent new usages of io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-03 23:23:24 +02:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-26 11:38:46 +01:00
Maciej Borzecki
6fb6396bb8 osutil, many: rename to MustBeTestBinary
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-07-20 11:46:29 +02:00
Maciej Borzecki
d127b295c1 many: use the helper for checking current binary is a test one
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-07-17 17:55:35 +02:00
Ian Johnson
588875e19f many: use more specific check for unit test mocking
Currently, if you try to use a snap with an app named "test", os.Args will also
end in ".test", making numerous places in the codebase think that it is being
run in a test environment and behave differently. In the case of the reported
bug, the code panics from `snap run` as it seems to the mountinfo code that we
are not mocking something that we should always be mocking in unit tests.

The bug could still hypothetically happen if someone made a symlink from 
somewhere with "go-build" in the path (but not as part of the app name in the
snap) and a .test suffix on the executable, but this is sufficiently specific
that it is highly unlikely we would ever actually run into that problem "in the
wild".

Fixes: https://bugs.launchpad.net/snapd/+bug/1886786

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-07-08 06:55:51 -05:00
Samuele Pedroni
bff4708f87 bootloader: use binary.Read/Write
the code I added recently is actually much simpler using
binary.Read/Write which apparently I ignored or forgot about
2020-04-18 18:41:44 +02:00
Samuele Pedroni
bbda8a5543 bootloader/efi: follow-up: whitespace, improve error, add TODO
also adds a todo about considering golang.org/x/text/encoding/unicode

thanks @anonymouse64
2020-04-15 10:30:06 +02:00
Samuele Pedroni
e17b91044b bootloader/efi: fix typos, improve comments
thanks @cmatsuoka
2020-04-14 21:16:33 +02:00
Samuele Pedroni
88dbdd0be3 boot,bootloader: split efi var reading into bytes vs strings
split ReadEfiVar into ReadVarBytes, ReadVarString,

support returning the actual attributes as well

strings seem to be typically UTF16 encoded, that needs
special handling

have a special ErrNoEFISystem to denote non-EFI systems

adapt mocking to all of this
2020-04-14 19:30:35 +02:00
Ian Johnson
c13696bf63 bootloader/efi: add MockEfiVariables to mock specific efi variable values
This is only meant to be used from tests, but it must be exported for other pkgs
to be able to use it.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-04-13 17:47:43 -05:00
Ian Johnson
cf0e9b40e0 bootloader: add efi pkg for reading EFI variables
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-04-13 17:40:28 -05:00