github.com/anonymouse64/snapd@v0.0.0-20210824153203-04c4c42d842d/boot/booted_kernel_partition_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2020 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package boot_test
    21  
    22  import (
    23  	. "gopkg.in/check.v1"
    24  
    25  	"github.com/snapcore/snapd/boot"
    26  	"github.com/snapcore/snapd/bootloader/bootloadertest"
    27  	"github.com/snapcore/snapd/bootloader/efi"
    28  	"github.com/snapcore/snapd/dirs"
    29  	"github.com/snapcore/snapd/testutil"
    30  )
    31  
    32  var _ = Suite(&bootedKernelPartitionSuite{})
    33  
    34  type bootedKernelPartitionSuite struct {
    35  	testutil.BaseTest
    36  }
    37  
    38  func (s *bootedKernelPartitionSuite) SetUpTest(c *C) {
    39  	dirs.SetRootDir(c.MkDir())
    40  	s.AddCleanup(func() { dirs.SetRootDir("") })
    41  }
    42  
    43  func (s *bootedKernelPartitionSuite) TestFindPartitionUUIDForBootedKernelDisk(c *C) {
    44  	restore := efi.MockVars(map[string][]byte{
    45  		"LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f": bootloadertest.UTF16Bytes("A9F5C949-AB89-5B47-A7BF-56DD28F96E65"),
    46  	}, nil)
    47  	defer restore()
    48  
    49  	partuuid, err := boot.FindPartitionUUIDForBootedKernelDisk()
    50  	c.Assert(err, IsNil)
    51  	c.Assert(partuuid, Equals, "a9f5c949-ab89-5b47-a7bf-56dd28f96e65")
    52  }
    53  
    54  func (s *bootedKernelPartitionSuite) TestFindPartitionUUIDForBootedKernelDiskNoEFISystem(c *C) {
    55  	restore := efi.MockVars(nil, nil)
    56  	defer restore()
    57  
    58  	_, err := boot.FindPartitionUUIDForBootedKernelDisk()
    59  	c.Check(err, Equals, efi.ErrNoEFISystem)
    60  }