github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/cmd/snap-repair/trace_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 main_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  )
    31  
    32  func makeMockRepairState(c *C) {
    33  	// the canonical script dir content
    34  	basedir := filepath.Join(dirs.SnapRepairRunDir, "canonical/1")
    35  	err := os.MkdirAll(basedir, 0700)
    36  	c.Assert(err, IsNil)
    37  	err = ioutil.WriteFile(filepath.Join(basedir, "r3.retry"), []byte("repair: canonical-1\nsummary: repair one\noutput:\nretry output"), 0600)
    38  	c.Assert(err, IsNil)
    39  	err = ioutil.WriteFile(filepath.Join(basedir, "r3.script"), []byte("#!/bin/sh\necho retry output"), 0700)
    40  	c.Assert(err, IsNil)
    41  
    42  	// my-brand
    43  	basedir = filepath.Join(dirs.SnapRepairRunDir, "my-brand/1")
    44  	err = os.MkdirAll(basedir, 0700)
    45  	c.Assert(err, IsNil)
    46  	err = ioutil.WriteFile(filepath.Join(basedir, "r1.done"), []byte("repair: my-brand-1\nsummary: my-brand repair one\noutput:\ndone output"), 0600)
    47  	c.Assert(err, IsNil)
    48  	err = ioutil.WriteFile(filepath.Join(basedir, "r1.script"), []byte("#!/bin/sh\necho done output"), 0700)
    49  	c.Assert(err, IsNil)
    50  
    51  	basedir = filepath.Join(dirs.SnapRepairRunDir, "my-brand/2")
    52  	err = os.MkdirAll(basedir, 0700)
    53  	c.Assert(err, IsNil)
    54  	err = ioutil.WriteFile(filepath.Join(basedir, "r2.skip"), []byte("repair: my-brand-2\nsummary: my-brand repair two\noutput:\nskip output"), 0600)
    55  	c.Assert(err, IsNil)
    56  	err = ioutil.WriteFile(filepath.Join(basedir, "r2.script"), []byte("#!/bin/sh\necho skip output"), 0700)
    57  	c.Assert(err, IsNil)
    58  
    59  	basedir = filepath.Join(dirs.SnapRepairRunDir, "my-brand/3")
    60  	err = os.MkdirAll(basedir, 0700)
    61  	c.Assert(err, IsNil)
    62  	err = ioutil.WriteFile(filepath.Join(basedir, "r0.running"), []byte("repair: my-brand-3\nsummary: my-brand repair three\noutput:\nrunning output"), 0600)
    63  	c.Assert(err, IsNil)
    64  	err = ioutil.WriteFile(filepath.Join(basedir, "r0.script"), []byte("#!/bin/sh\necho running output"), 0700)
    65  	c.Assert(err, IsNil)
    66  }