github.com/Lephar/snapd@v0.0.0-20210825215435-c7fba9cef4d2/overlord/configstate/configcore/experimental_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 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 configcore_test 21 22 import ( 23 "fmt" 24 "path/filepath" 25 26 . "gopkg.in/check.v1" 27 28 "github.com/snapcore/snapd/features" 29 "github.com/snapcore/snapd/osutil" 30 "github.com/snapcore/snapd/overlord/configstate/configcore" 31 "github.com/snapcore/snapd/testutil" 32 ) 33 34 type experimentalSuite struct { 35 configcoreSuite 36 } 37 38 var _ = Suite(&experimentalSuite{}) 39 40 func featureConf(feature features.SnapdFeature) string { 41 return "experimental." + feature.String() 42 } 43 44 func (s *experimentalSuite) TestConfigureExperimentalSettingsInvalid(c *C) { 45 for _, feature := range features.KnownFeatures() { 46 conf := &mockConf{ 47 state: s.state, 48 changes: map[string]interface{}{featureConf(feature): "foo"}, 49 } 50 err := configcore.Run(classicDev, conf) 51 c.Check(err, ErrorMatches, fmt.Sprintf(`%s can only be set to 'true' or 'false'`, featureConf(feature))) 52 } 53 } 54 55 func (s *experimentalSuite) TestConfigureExperimentalSettingsHappy(c *C) { 56 for _, feature := range features.KnownFeatures() { 57 for _, t := range []string{"true", "false"} { 58 conf := &mockConf{ 59 state: s.state, 60 conf: map[string]interface{}{featureConf(feature): t}, 61 } 62 err := configcore.Run(classicDev, conf) 63 c.Check(err, IsNil) 64 } 65 } 66 } 67 68 func (s *experimentalSuite) TestExportedFeatures(c *C) { 69 conf := &mockConf{ 70 state: s.state, 71 conf: map[string]interface{}{featureConf(features.PerUserMountNamespace): true}, 72 } 73 err := configcore.Run(classicDev, conf) 74 c.Assert(err, IsNil) 75 c.Check(features.PerUserMountNamespace.ControlFile(), testutil.FilePresent) 76 77 delete(conf.changes, "experimental.per-user-mount-namespace") 78 err = configcore.Run(classicDev, conf) 79 c.Assert(err, IsNil) 80 c.Check(features.PerUserMountNamespace.ControlFile(), testutil.FilePresent) 81 } 82 83 func (s *experimentalSuite) TestFilesystemOnlyApply(c *C) { 84 conf := configcore.PlainCoreConfig(map[string]interface{}{ 85 "experimental.refresh-app-awareness": "true", 86 }) 87 tmpDir := c.MkDir() 88 c.Assert(configcore.FilesystemOnlyApply(classicDev, tmpDir, conf), IsNil) 89 c.Check(osutil.FileExists(filepath.Join(tmpDir, "/var/lib/snapd/features/refresh-app-awareness")), Equals, true) 90 } 91 92 func (s *experimentalSuite) TestFilesystemOnlyApplyValidationFails(c *C) { 93 conf := configcore.PlainCoreConfig(map[string]interface{}{ 94 "experimental.refresh-app-awareness": 1, 95 }) 96 tmpDir := c.MkDir() 97 c.Assert(configcore.FilesystemOnlyApply(classicDev, tmpDir, conf), ErrorMatches, `experimental.refresh-app-awareness can only be set to 'true' or 'false'`) 98 }