diff options
| author | Pawel Stolowski <stolowski@gmail.com> | 2018-03-20 21:12:31 +0100 |
|---|---|---|
| committer | Pawel Stolowski <stolowski@gmail.com> | 2018-03-20 21:12:31 +0100 |
| commit | 467c0ad980bbc80c65dec16acae2813dce2cded1 (patch) | |
| tree | 908831ce35bdb634026affb146106e743cf3d2d3 | |
| parent | 21e7690ccd848bf07e51e5c249f3f4e9fbfa6ec4 (diff) | |
Fix remaining tests.fix-sanitize
| -rw-r--r-- | asserts/ifacedecls_test.go | 15 | ||||
| -rw-r--r-- | boot/kernel_os_test.go | 4 | ||||
| -rw-r--r-- | daemon/api_test.go | 4 | ||||
| -rw-r--r-- | image/image_test.go | 5 | ||||
| -rw-r--r-- | interfaces/apparmor/spec_test.go | 10 | ||||
| -rw-r--r-- | interfaces/connection_test.go | 8 | ||||
| -rw-r--r-- | interfaces/core_test.go | 14 | ||||
| -rw-r--r-- | interfaces/ifacetest/backendtest.go | 12 | ||||
| -rw-r--r-- | interfaces/policy/basedeclaration_test.go | 8 | ||||
| -rw-r--r-- | interfaces/policy/policy_test.go | 7 | ||||
| -rw-r--r-- | interfaces/repo_test.go | 24 | ||||
| -rw-r--r-- | overlord/managers_test.go | 4 | ||||
| -rw-r--r-- | overlord/snapstate/backend/backend_test.go | 17 | ||||
| -rw-r--r-- | overlord/snapstate/backend/setup_test.go | 5 | ||||
| -rw-r--r-- | snap/container_test.go | 12 | ||||
| -rw-r--r-- | snap/info_snap_yaml_test.go | 19 | ||||
| -rw-r--r-- | snap/pack/pack_test.go | 5 | ||||
| -rw-r--r-- | snap/snapenv/snapenv_test.go | 9 | ||||
| -rw-r--r-- | snap/snaptest/snaptest.go | 11 | ||||
| -rw-r--r-- | snap/validate_test.go | 15 | ||||
| -rw-r--r-- | store/details_v2_test.go | 13 | ||||
| -rw-r--r-- | store/store_test.go | 4 | ||||
| -rw-r--r-- | tests/lib/fakestore/store/store.go | 6 | ||||
| -rw-r--r-- | wrappers/desktop_test.go | 17 | ||||
| -rw-r--r-- | wrappers/services_gen_test.go | 14 |
25 files changed, 246 insertions, 16 deletions
diff --git a/asserts/ifacedecls_test.go b/asserts/ifacedecls_test.go index 8b274e89af..405630a746 100644 --- a/asserts/ifacedecls_test.go +++ b/asserts/ifacedecls_test.go @@ -28,6 +28,8 @@ import ( "github.com/snapcore/snapd/asserts" "github.com/snapcore/snapd/snap" + + "github.com/snapcore/snapd/testutil" ) var ( @@ -35,7 +37,9 @@ var ( _ = Suite(&plugSlotRulesSuite{}) ) -type attrConstraintsSuite struct{} +type attrConstraintsSuite struct { + testutil.BaseTest +} func attrs(yml string) map[string]interface{} { var attrs map[string]interface{} @@ -59,6 +63,15 @@ func attrs(yml string) map[string]interface{} { return info.Plugs["plug"].Attrs } +func (s *attrConstraintsSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *attrConstraintsSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *attrConstraintsSuite) TestSimple(c *C) { m, err := asserts.ParseHeaders([]byte(`attrs: foo: FOO diff --git a/boot/kernel_os_test.go b/boot/kernel_os_test.go index 7e37cd5211..06334f573b 100644 --- a/boot/kernel_os_test.go +++ b/boot/kernel_os_test.go @@ -39,18 +39,22 @@ import ( func TestBoot(t *testing.T) { TestingT(t) } type kernelOSSuite struct { + testutil.BaseTest bootloader *boottest.MockBootloader } var _ = Suite(&kernelOSSuite{}) func (s *kernelOSSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) dirs.SetRootDir(c.MkDir()) s.bootloader = boottest.NewMockBootloader("mock", c.MkDir()) partition.ForceBootloader(s.bootloader) } func (s *kernelOSSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) dirs.SetRootDir("") partition.ForceBootloader(nil) } diff --git a/daemon/api_test.go b/daemon/api_test.go index f4247a4668..9234276308 100644 --- a/daemon/api_test.go +++ b/daemon/api_test.go @@ -104,6 +104,8 @@ type apiBaseSuite struct { jctlFollows []bool jctlRCs []io.ReadCloser jctlErrs []error + + restoreSanitize func() } func (s *apiBaseSuite) SnapInfo(spec store.SnapSpec, user *auth.UserState) (*snap.Info, error) { @@ -165,6 +167,7 @@ func (s *apiBaseSuite) SetUpSuite(c *check.C) { s.restoreRelease = release.MockForcedDevmode(false) s.systemctlRestorer = systemd.MockSystemctl(s.systemctl) s.journalctlRestorer = systemd.MockJournalctl(s.journalctl) + s.restoreSanitize = snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) } func (s *apiBaseSuite) TearDownSuite(c *check.C) { @@ -172,6 +175,7 @@ func (s *apiBaseSuite) TearDownSuite(c *check.C) { s.restoreRelease() s.systemctlRestorer() s.journalctlRestorer() + s.restoreSanitize() } func (s *apiBaseSuite) systemctl(args ...string) (buf []byte, err error) { diff --git a/image/image_test.go b/image/image_test.go index daed65a479..51b0e84ab0 100644 --- a/image/image_test.go +++ b/image/image_test.go @@ -64,6 +64,7 @@ func (s *emptyStore) Assertion(assertType *asserts.AssertionType, primaryKey []s func Test(t *testing.T) { TestingT(t) } type imageSuite struct { + testutil.BaseTest root string bootloader *boottest.MockBootloader @@ -87,6 +88,9 @@ func (s *imageSuite) SetUpTest(c *C) { s.bootloader = boottest.NewMockBootloader("grub", c.MkDir()) partition.ForceBootloader(s.bootloader) + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + s.stdout = &bytes.Buffer{} image.Stdout = s.stdout s.stderr = &bytes.Buffer{} @@ -159,6 +163,7 @@ func (s *imageSuite) addSystemSnapAssertions(c *C, snapName string, publisher st } func (s *imageSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) partition.ForceBootloader(nil) image.Stdout = os.Stdout image.Stderr = os.Stderr diff --git a/interfaces/apparmor/spec_test.go b/interfaces/apparmor/spec_test.go index f7677ea019..225400336b 100644 --- a/interfaces/apparmor/spec_test.go +++ b/interfaces/apparmor/spec_test.go @@ -27,9 +27,12 @@ import ( "github.com/snapcore/snapd/interfaces/ifacetest" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/snaptest" + + "github.com/snapcore/snapd/testutil" ) type specSuite struct { + testutil.BaseTest iface *ifacetest.TestInterface spec *apparmor.Specification plugInfo *snap.PlugInfo @@ -83,11 +86,18 @@ var _ = Suite(&specSuite{ }) func (s *specSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + s.spec = &apparmor.Specification{} s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil) s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil) } +func (s *specSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + // The spec.Specification can be used through the interfaces.Specification interface func (s *specSuite) TestSpecificationIface(c *C) { var r interfaces.Specification = s.spec diff --git a/interfaces/connection_test.go b/interfaces/connection_test.go index 30f9efdb5f..10cc706a36 100644 --- a/interfaces/connection_test.go +++ b/interfaces/connection_test.go @@ -24,9 +24,11 @@ import ( "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/snaptest" + "github.com/snapcore/snapd/testutil" ) type connSuite struct { + testutil.BaseTest plug *snap.PlugInfo slot *snap.SlotInfo } @@ -34,6 +36,8 @@ type connSuite struct { var _ = Suite(&connSuite{}) func (s *connSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) consumer := snaptest.MockInfo(c, ` name: consumer version: 0 @@ -58,6 +62,10 @@ slots: s.slot = producer.Slots["slot"] } +func (s *connSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + // Make sure ConnectedPlug,ConnectedSlot, PlugInfo, SlotInfo implement Attrer. var _ Attrer = (*ConnectedPlug)(nil) var _ Attrer = (*ConnectedSlot)(nil) diff --git a/interfaces/core_test.go b/interfaces/core_test.go index 17dd0ea2e1..236a32b89a 100644 --- a/interfaces/core_test.go +++ b/interfaces/core_test.go @@ -29,16 +29,28 @@ import ( "github.com/snapcore/snapd/interfaces/ifacetest" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/snaptest" + "github.com/snapcore/snapd/testutil" ) func Test(t *testing.T) { TestingT(t) } -type CoreSuite struct{} +type CoreSuite struct { + testutil.BaseTest +} var _ = Suite(&CoreSuite{}) +func (s *CoreSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *CoreSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *CoreSuite) TestValidateName(c *C) { validNames := []string{ "a", "aa", "aaa", "aaaa", diff --git a/interfaces/ifacetest/backendtest.go b/interfaces/ifacetest/backendtest.go index 652b1e9b02..091e5635b9 100644 --- a/interfaces/ifacetest/backendtest.go +++ b/interfaces/ifacetest/backendtest.go @@ -29,10 +29,11 @@ import ( ) type BackendSuite struct { - Backend interfaces.SecurityBackend - Repo *interfaces.Repository - Iface *TestInterface - RootDir string + Backend interfaces.SecurityBackend + Repo *interfaces.Repository + Iface *TestInterface + RootDir string + restoreSanitize func() } func (s *BackendSuite) SetUpTest(c *C) { @@ -44,10 +45,13 @@ func (s *BackendSuite) SetUpTest(c *C) { s.Iface = &TestInterface{InterfaceName: "iface"} err := s.Repo.AddInterface(s.Iface) c.Assert(err, IsNil) + + s.restoreSanitize = snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) } func (s *BackendSuite) TearDownTest(c *C) { dirs.SetRootDir("/") + s.restoreSanitize() } // Tests for Setup() and Remove() diff --git a/interfaces/policy/basedeclaration_test.go b/interfaces/policy/basedeclaration_test.go index 66fdc547ab..9bb4b5c428 100644 --- a/interfaces/policy/basedeclaration_test.go +++ b/interfaces/policy/basedeclaration_test.go @@ -37,15 +37,21 @@ import ( ) type baseDeclSuite struct { - baseDecl *asserts.BaseDeclaration + baseDecl *asserts.BaseDeclaration + restoreSanitize func() } var _ = Suite(&baseDeclSuite{}) func (s *baseDeclSuite) SetUpSuite(c *C) { + s.restoreSanitize = snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) s.baseDecl = asserts.BuiltinBaseDeclaration() } +func (s *baseDeclSuite) TearDownSuite(c *C) { + s.restoreSanitize() +} + func (s *baseDeclSuite) connectCand(c *C, iface, slotYaml, plugYaml string) *policy.ConnectCandidate { if slotYaml == "" { slotYaml = fmt.Sprintf(`name: slot-snap diff --git a/interfaces/policy/policy_test.go b/interfaces/policy/policy_test.go index d929eac854..ac0c5642e8 100644 --- a/interfaces/policy/policy_test.go +++ b/interfaces/policy/policy_test.go @@ -45,11 +45,14 @@ type policySuite struct { randomSnap *snap.Info randomDecl *asserts.SnapDeclaration + + restoreSanitize func() } var _ = Suite(&policySuite{}) func (s *policySuite) SetUpSuite(c *C) { + s.restoreSanitize = snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) a, err := asserts.Decode([]byte(`type: base-declaration authority-id: canonical series: 16 @@ -704,6 +707,10 @@ AXNpZw==`)) s.randomDecl = a.(*asserts.SnapDeclaration) } +func (s *policySuite) TearDownSuite(c *C) { + s.restoreSanitize() +} + func (s *policySuite) TestBaselineDefaultIsAllow(c *C) { cand := policy.ConnectCandidate{ Plug: s.plugSnap.Plugs["random"], diff --git a/interfaces/repo_test.go b/interfaces/repo_test.go index 6f28c14b69..e270dd719a 100644 --- a/interfaces/repo_test.go +++ b/interfaces/repo_test.go @@ -32,6 +32,7 @@ import ( ) type RepositorySuite struct { + testutil.BaseTest iface Interface plug *snap.PlugInfo slot *snap.SlotInfo @@ -48,6 +49,9 @@ var _ = Suite(&RepositorySuite{ }) func (s *RepositorySuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + consumer := snaptest.MockInfo(c, ` name: consumer version: 0 @@ -93,6 +97,10 @@ slots: c.Assert(err, IsNil) } +func (s *RepositorySuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func addPlugsSlots(c *C, repo *Repository, yamls ...string) []*snap.Info { result := make([]*snap.Info, len(yamls)) for i, yaml := range yamls { @@ -1488,12 +1496,16 @@ plugs: // Tests for AddSnap and RemoveSnap type AddRemoveSuite struct { + testutil.BaseTest repo *Repository } var _ = Suite(&AddRemoveSuite{}) func (s *AddRemoveSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + s.repo = NewRepository() err := s.repo.AddInterface(&ifacetest.TestInterface{InterfaceName: "iface"}) c.Assert(err, IsNil) @@ -1505,6 +1517,10 @@ func (s *AddRemoveSuite) SetUpTest(c *C) { c.Assert(err, IsNil) } +func (s *AddRemoveSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + const testConsumerYaml = ` name: consumer version: 0 @@ -1632,6 +1648,7 @@ func (s *AddRemoveSuite) TestRemoveSnapErrorsOnStillConnectedSlot(c *C) { } type DisconnectSnapSuite struct { + testutil.BaseTest repo *Repository s1, s2 *snap.Info } @@ -1639,6 +1656,9 @@ type DisconnectSnapSuite struct { var _ = Suite(&DisconnectSnapSuite{}) func (s *DisconnectSnapSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + s.repo = NewRepository() err := s.repo.AddInterface(&ifacetest.TestInterface{InterfaceName: "iface-a"}) @@ -1670,6 +1690,10 @@ slots: c.Assert(err, IsNil) } +func (s *DisconnectSnapSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *DisconnectSnapSuite) TestNotConnected(c *C) { affected, err := s.repo.DisconnectSnap("s1") c.Assert(err, IsNil) diff --git a/overlord/managers_test.go b/overlord/managers_test.go index 9e8a3a3bb6..e70955dcfa 100644 --- a/overlord/managers_test.go +++ b/overlord/managers_test.go @@ -747,6 +747,10 @@ slots: err = assertstate.Add(st, snapDecl) c.Assert(err, IsNil) + // mock SanitizePlugsSlots so that unknown interfaces are not rejected + restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() + ts, err := snapstate.InstallPath(st, si, snapPath, "", snapstate.Flags{DevMode: true}) c.Assert(err, IsNil) chg := st.NewChange("install-snap", "...") diff --git a/overlord/snapstate/backend/backend_test.go b/overlord/snapstate/backend/backend_test.go index 71e10992a4..f06ca48276 100644 --- a/overlord/snapstate/backend/backend_test.go +++ b/overlord/snapstate/backend/backend_test.go @@ -29,13 +29,13 @@ import ( "github.com/snapcore/snapd/snap/squashfs" "github.com/snapcore/snapd/overlord/snapstate/backend" + "github.com/snapcore/snapd/testutil" ) func TestBackend(t *testing.T) { TestingT(t) } func makeTestSnap(c *C, snapYamlContent string) string { - info, err := snap.InfoFromSnapYaml([]byte(snapYamlContent)) - c.Assert(err, IsNil) + info := snaptest.MockInfo(c, snapYamlContent, nil) var files [][]string for _, app := range info.Apps { // files is a list of (filename, content) @@ -44,10 +44,21 @@ func makeTestSnap(c *C, snapYamlContent string) string { return snaptest.MakeTestSnapWithFiles(c, snapYamlContent, files) } -type backendSuite struct{} +type backendSuite struct { + testutil.BaseTest +} var _ = Suite(&backendSuite{}) +func (s *backendSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *backendSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *backendSuite) TestOpenSnapFile(c *C) { const yaml = `name: hello version: 1.0 diff --git a/overlord/snapstate/backend/setup_test.go b/overlord/snapstate/backend/setup_test.go index 8bbc64c607..c31fb9b69f 100644 --- a/overlord/snapstate/backend/setup_test.go +++ b/overlord/snapstate/backend/setup_test.go @@ -40,6 +40,7 @@ import ( ) type setupSuite struct { + testutil.BaseTest be backend.Backend umount *testutil.MockCmd systemctlRestorer func() @@ -48,6 +49,9 @@ type setupSuite struct { var _ = Suite(&setupSuite{}) func (s *setupSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + dirs.SetRootDir(c.MkDir()) err := os.MkdirAll(filepath.Join(dirs.GlobalRootDir, "etc", "systemd", "system", "multi-user.target.wants"), 0755) @@ -61,6 +65,7 @@ func (s *setupSuite) SetUpTest(c *C) { } func (s *setupSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) dirs.SetRootDir("") partition.ForceBootloader(nil) s.umount.Restore() diff --git a/snap/container_test.go b/snap/container_test.go index cb5b077c24..a1dff4bcb0 100644 --- a/snap/container_test.go +++ b/snap/container_test.go @@ -29,6 +29,8 @@ import ( "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/snapdir" + + "github.com/snapcore/snapd/testutil" ) type FileSuite struct{} @@ -55,6 +57,7 @@ func (s *FileSuite) TestFileOpenForSnapDirErrors(c *C) { } type validateSuite struct { + testutil.BaseTest log func(string, ...interface{}) } @@ -62,6 +65,15 @@ var _ = Suite(&validateSuite{}) func discard(string, ...interface{}) {} +func (s *validateSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *validateSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *validateSuite) TestValidateContainerReallyEmptyFails(c *C) { const yaml = `name: empty-snap version: 1 diff --git a/snap/info_snap_yaml_test.go b/snap/info_snap_yaml_test.go index 8eb582a6d5..3abe23d4f1 100644 --- a/snap/info_snap_yaml_test.go +++ b/snap/info_snap_yaml_test.go @@ -29,12 +29,16 @@ import ( "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/strutil" "github.com/snapcore/snapd/timeout" + + "github.com/snapcore/snapd/testutil" ) // Hook up check.v1 into the "go test" runner func Test(t *testing.T) { TestingT(t) } -type InfoSnapYamlTestSuite struct{} +type InfoSnapYamlTestSuite struct { + testutil.BaseTest +} var _ = Suite(&InfoSnapYamlTestSuite{}) @@ -43,6 +47,15 @@ version: 1.0 type: app `) +func (s *InfoSnapYamlTestSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *InfoSnapYamlTestSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *InfoSnapYamlTestSuite) TestSimple(c *C) { info, err := snap.InfoFromSnapYaml(mockYaml) c.Assert(err, IsNil) @@ -58,16 +71,20 @@ func (s *InfoSnapYamlTestSuite) TestFail(c *C) { type YamlSuite struct { restore func() + testutil.BaseTest } var _ = Suite(&YamlSuite{}) func (s *YamlSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) hookType := snap.NewHookType(regexp.MustCompile(".*")) s.restore = snap.MockSupportedHookTypes([]*snap.HookType{hookType}) } func (s *YamlSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) s.restore() } diff --git a/snap/pack/pack_test.go b/snap/pack/pack_test.go index 245d7ed3ab..c3d9e9c47e 100644 --- a/snap/pack/pack_test.go +++ b/snap/pack/pack_test.go @@ -48,6 +48,7 @@ var _ = Suite(&packSuite{}) func (s *packSuite) SetUpTest(c *C) { s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) // chdir into a tempdir pwd, err := os.Getwd() @@ -60,6 +61,10 @@ func (s *packSuite) SetUpTest(c *C) { dirs.SetRootDir(c.MkDir()) } +func (s *packSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func makeExampleSnapSourceDir(c *C, snapYamlContent string) string { tempdir := c.MkDir() c.Assert(os.Chmod(tempdir, 0755), IsNil) diff --git a/snap/snapenv/snapenv_test.go b/snap/snapenv/snapenv_test.go index 55eda8a995..34f44f2355 100644 --- a/snap/snapenv/snapenv_test.go +++ b/snap/snapenv/snapenv_test.go @@ -68,6 +68,15 @@ var mockClassicSnapInfo = &snap.Info{ Confinement: snap.ClassicConfinement, } +func (s *HTestSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *HTestSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (ts *HTestSuite) TestBasic(c *C) { env := basicEnv(mockSnapInfo) diff --git a/snap/snaptest/snaptest.go b/snap/snaptest/snaptest.go index cb261c14c8..07d132e4a0 100644 --- a/snap/snaptest/snaptest.go +++ b/snap/snaptest/snaptest.go @@ -40,6 +40,9 @@ import ( func MockSnap(c *check.C, yamlText string, sideInfo *snap.SideInfo) *snap.Info { c.Assert(sideInfo, check.Not(check.IsNil)) + restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() + // Parse the yaml (we need the Name). snapInfo, err := snap.InfoFromSnapYaml([]byte(yamlText)) c.Assert(err, check.IsNil) @@ -75,8 +78,8 @@ func MockInfo(c *check.C, yamlText string, sideInfo *snap.SideInfo) *snap.Info { } restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() snapInfo, err := snap.InfoFromSnapYaml([]byte(yamlText)) - restoreSanitize() c.Assert(err, check.IsNil) snapInfo.SideInfo = *sideInfo err = snap.Validate(snapInfo) @@ -93,6 +96,9 @@ func MockInvalidInfo(c *check.C, yamlText string, sideInfo *snap.SideInfo) *snap sideInfo = &snap.SideInfo{} } + restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() + snapInfo, err := snap.InfoFromSnapYaml([]byte(yamlText)) c.Assert(err, check.IsNil) snapInfo.SideInfo = *sideInfo @@ -137,6 +143,9 @@ func MakeTestSnapWithFiles(c *check.C, snapYamlContent string, files [][]string) PopulateDir(snapSource, files) + restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() + err = osutil.ChDir(snapSource, func() error { var err error snapFilePath, err = pack.Snap(snapSource, "") diff --git a/snap/validate_test.go b/snap/validate_test.go index c13df5a920..77e324ef0c 100644 --- a/snap/validate_test.go +++ b/snap/validate_test.go @@ -27,9 +27,13 @@ import ( . "gopkg.in/check.v1" . "github.com/snapcore/snapd/snap" + + "github.com/snapcore/snapd/testutil" ) -type ValidateSuite struct{} +type ValidateSuite struct { + testutil.BaseTest +} var _ = Suite(&ValidateSuite{}) @@ -55,6 +59,15 @@ func createSampleApp() *AppInfo { return app } +func (s *ValidateSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(MockSanitizePlugsSlots(func(snapInfo *Info) {})) +} + +func (s *ValidateSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *ValidateSuite) TestValidateName(c *C) { validNames := []string{ "a", "aa", "aaa", "aaaa", diff --git a/store/details_v2_test.go b/store/details_v2_test.go index ce048c9f8f..7389762189 100644 --- a/store/details_v2_test.go +++ b/store/details_v2_test.go @@ -31,7 +31,9 @@ import ( "github.com/snapcore/snapd/testutil" ) -type detailsV2Suite struct{} +type detailsV2Suite struct { + testutil.BaseTest +} var _ = Suite(&detailsV2Suite{}) @@ -125,6 +127,15 @@ const ( }` ) +func (s *detailsV2Suite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *detailsV2Suite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *detailsV2Suite) TestInfoFromStoreSnapSimple(c *C) { var snp storeSnap err := json.Unmarshal([]byte(coreStoreJSON), &snp) diff --git a/store/store_test.go b/store/store_test.go index 7b914704da..b41b24bdd9 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -349,6 +349,9 @@ func createTestDevice() *auth.DeviceState { } func (s *storeTestSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) + s.store = New(nil, nil) s.origDownloadFunc = download dirs.SetRootDir(c.MkDir()) @@ -385,6 +388,7 @@ func (s *storeTestSuite) TearDownTest(c *C) { download = s.origDownloadFunc s.mockXDelta.Restore() s.restoreLogger() + s.BaseTest.TearDownTest(c) } func (s *storeTestSuite) expectedAuthorization(c *C, user *auth.UserState) string { diff --git a/tests/lib/fakestore/store/store.go b/tests/lib/fakestore/store/store.go index fcb5948195..4edde0b32b 100644 --- a/tests/lib/fakestore/store/store.go +++ b/tests/lib/fakestore/store/store.go @@ -180,6 +180,9 @@ func snapEssentialInfo(w http.ResponseWriter, fn, snapID string, bs asserts.Back return nil, errInfo } + restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() + info, err := snap.ReadInfoFromSnapFile(snapFile, nil) if err != nil { http.Error(w, fmt.Sprintf("can get info for: %v: %v", fn, err), 400) @@ -312,6 +315,9 @@ func (s *Store) collectSnaps() (map[string]string, error) { snaps := map[string]string{} + restoreSanitize := snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {}) + defer restoreSanitize() + for _, fn := range snapFns { snapFile, err := snap.Open(fn) if err != nil { diff --git a/wrappers/desktop_test.go b/wrappers/desktop_test.go index 188529ace1..982f15ce93 100644 --- a/wrappers/desktop_test.go +++ b/wrappers/desktop_test.go @@ -36,6 +36,7 @@ import ( ) type desktopSuite struct { + testutil.BaseTest tempdir string mockUpdateDesktopDatabase *testutil.MockCmd @@ -44,6 +45,8 @@ type desktopSuite struct { var _ = Suite(&desktopSuite{}) func (s *desktopSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) s.tempdir = c.MkDir() dirs.SetRootDir(s.tempdir) @@ -51,6 +54,7 @@ func (s *desktopSuite) SetUpTest(c *C) { } func (s *desktopSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) s.mockUpdateDesktopDatabase.Restore() dirs.SetRootDir("") } @@ -133,10 +137,21 @@ func (s *desktopSuite) TestAddPackageDesktopFilesCleanup(c *C) { // sanitize -type sanitizeDesktopFileSuite struct{} +type sanitizeDesktopFileSuite struct { + testutil.BaseTest +} var _ = Suite(&sanitizeDesktopFileSuite{}) +func (s *sanitizeDesktopFileSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *sanitizeDesktopFileSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *sanitizeDesktopFileSuite) TestSanitizeIgnoreNotWhitelisted(c *C) { snap := &snap.Info{SideInfo: snap.SideInfo{RealName: "foo", Revision: snap.R(12)}} desktopContent := []byte(`[Desktop Entry] diff --git a/wrappers/services_gen_test.go b/wrappers/services_gen_test.go index 286708d8de..090701d783 100644 --- a/wrappers/services_gen_test.go +++ b/wrappers/services_gen_test.go @@ -30,12 +30,15 @@ import ( "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/snaptest" + "github.com/snapcore/snapd/testutil" "github.com/snapcore/snapd/timeout" "github.com/snapcore/snapd/timeutil" "github.com/snapcore/snapd/wrappers" ) -type servicesWrapperGenSuite struct{} +type servicesWrapperGenSuite struct { + testutil.BaseTest +} var _ = Suite(&servicesWrapperGenSuite{}) @@ -95,6 +98,15 @@ Type=%s expectedTypeForkingWrapper = fmt.Sprintf(expectedServiceWrapperFmt, mountUnitPrefix, mountUnitPrefix, "forking", "\n[Install]\nWantedBy=multi-user.target\n") ) +func (s *servicesWrapperGenSuite) SetUpTest(c *C) { + s.BaseTest.SetUpTest(c) + s.BaseTest.AddCleanup(snap.MockSanitizePlugsSlots(func(snapInfo *snap.Info) {})) +} + +func (s *servicesWrapperGenSuite) TearDownTest(c *C) { + s.BaseTest.TearDownTest(c) +} + func (s *servicesWrapperGenSuite) TestGenerateSnapServiceFile(c *C) { yamlText := ` name: snap |
