1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
// -*- Mode: Go; indent-tabs-mode: t -*-
//go:build withbootassetstesting
/*
* Copyright (C) 2021 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package bootloader_test
import (
"os"
"path/filepath"
. "gopkg.in/check.v1"
"github.com/snapcore/snapd/bootloader"
"github.com/snapcore/snapd/bootloader/assets"
"github.com/snapcore/snapd/snapdenv"
)
type withbootasetstestingTestSuite struct {
baseBootenvTestSuite
}
var _ = Suite(&withbootasetstestingTestSuite{})
func (s *withbootasetstestingTestSuite) TestInjects(c *C) {
d := c.MkDir()
c.Assert(os.WriteFile(filepath.Join(d, "bootassetstesting"), []byte("with-bootassetstesting\n"), 0644), IsNil)
restore := bootloader.MockMaybeInjectOsReadlink(func(_ string) (string, error) {
return filepath.Join(d, "foo"), nil
})
defer restore()
restore = snapdenv.MockTesting(true)
defer restore()
restore = assets.MockSnippetsForEdition("grub.cfg:static-cmdline", []assets.ForEditions{
{FirstEdition: 2, Snippet: []byte(`foo bar baz`)},
})
defer restore()
restore = assets.MockInternal("grub.cfg", []byte(`# Snapd-Boot-Config-Edition: 5
set snapd_static_cmdline_args='foo bar baz'
this is mocked grub-recovery.conf
`))
defer restore()
bootloader.MaybeInjectTestingBootloaderAssets()
bumped := assets.Internal("grub.cfg")
c.Check(string(bumped), Equals, `# Snapd-Boot-Config-Edition: 6
set snapd_static_cmdline_args='foo bar baz with-bootassetstesting'
this is mocked grub-recovery.conf
`)
cmdline := bootloader.StaticCommandLineForGrubAssetEdition("grub.cfg", 6)
c.Check(cmdline, Equals, `foo bar baz with-bootassetstesting`)
}
func (s *withbootasetstestingTestSuite) TestNoMarker(c *C) {
d := c.MkDir()
restore := bootloader.MockMaybeInjectOsReadlink(func(_ string) (string, error) {
return filepath.Join(d, "foo"), nil
})
defer restore()
restore = snapdenv.MockTesting(true)
defer restore()
restore = assets.MockSnippetsForEdition("grub.cfg:static-cmdline", []assets.ForEditions{
{FirstEdition: 2, Snippet: []byte(`foo bar baz`)},
})
defer restore()
grubCfg := `# Snapd-Boot-Config-Edition: 5
set snapd_static_cmdline_args='foo bar baz'
this is mocked grub-recovery.conf
`
restore = assets.MockInternal("grub.cfg", []byte(grubCfg))
defer restore()
bootloader.MaybeInjectTestingBootloaderAssets()
notBumped := assets.Internal("grub.cfg")
c.Check(string(notBumped), Equals, grubCfg)
cmdline := bootloader.StaticCommandLineForGrubAssetEdition("grub.cfg", 5)
c.Check(cmdline, Equals, `foo bar baz`)
}
|