github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/overlord/snapstate/readme_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 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 snapstate_test
    21  
    22  import (
    23  	"io/ioutil"
    24  	"os"
    25  	"path/filepath"
    26  
    27  	. "gopkg.in/check.v1"
    28  
    29  	"github.com/snapcore/snapd/dirs"
    30  	"github.com/snapcore/snapd/overlord/snapstate"
    31  	"github.com/snapcore/snapd/release"
    32  	"github.com/snapcore/snapd/testutil"
    33  )
    34  
    35  type readmeSuite struct{}
    36  
    37  var _ = Suite(&readmeSuite{})
    38  
    39  func (s *readmeSuite) TestSnapReadmeFedora(c *C) {
    40  	restore := release.MockReleaseInfo(&release.OS{ID: "fedora"})
    41  	defer restore()
    42  
    43  	dirs.SetRootDir("/")
    44  	defer dirs.SetRootDir("/")
    45  
    46  	c.Assert(snapstate.SnapReadme(), testutil.Contains, "/var/lib/snapd/snap/bin                   - Symlinks to snap applications.\n")
    47  }
    48  
    49  func (s *readmeSuite) TestSnapReadmeUbuntu(c *C) {
    50  	restore := release.MockReleaseInfo(&release.OS{ID: "ubuntu"})
    51  	defer restore()
    52  
    53  	dirs.SetRootDir("/")
    54  	defer dirs.SetRootDir("/")
    55  
    56  	c.Assert(snapstate.SnapReadme(), testutil.Contains, "/snap/bin                   - Symlinks to snap applications.\n")
    57  }
    58  
    59  func (s *readmeSuite) TestWriteSnapREADME(c *C) {
    60  	dirs.SetRootDir(c.MkDir())
    61  	defer dirs.SetRootDir("")
    62  
    63  	f := filepath.Join(dirs.SnapMountDir, "README")
    64  
    65  	// Missing file is created.
    66  	c.Assert(snapstate.WriteSnapReadme(), IsNil)
    67  	c.Check(f, testutil.FileContains, "https://forum.snapcraft.io/t/the-snap-directory/2817")
    68  
    69  	// Corrupted file is cured.
    70  	err := os.Remove(f)
    71  	c.Assert(err, IsNil)
    72  	err = ioutil.WriteFile(f, []byte("corrupted"), 0644)
    73  	c.Assert(err, IsNil)
    74  	c.Assert(snapstate.WriteSnapReadme(), IsNil)
    75  	c.Check(f, testutil.FileContains, "https://forum.snapcraft.io/t/the-snap-directory/2817")
    76  }