github.com/rigado/snapd@v2.42.5-go-mod+incompatible/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  
    25  	. "gopkg.in/check.v1"
    26  
    27  	"github.com/snapcore/snapd/features"
    28  	"github.com/snapcore/snapd/overlord/configstate/configcore"
    29  	"github.com/snapcore/snapd/testutil"
    30  )
    31  
    32  type experimentalSuite struct {
    33  	configcoreSuite
    34  }
    35  
    36  var _ = Suite(&experimentalSuite{})
    37  
    38  func featureConf(feature features.SnapdFeature) string {
    39  	return "experimental." + feature.String()
    40  }
    41  
    42  func (s *experimentalSuite) TestConfigureExperimentalSettingsInvalid(c *C) {
    43  	for _, feature := range features.KnownFeatures() {
    44  		conf := &mockConf{
    45  			state:   s.state,
    46  			changes: map[string]interface{}{featureConf(feature): "foo"},
    47  		}
    48  		err := configcore.Run(conf)
    49  		c.Check(err, ErrorMatches, fmt.Sprintf(`%s can only be set to 'true' or 'false'`, featureConf(feature)))
    50  	}
    51  }
    52  
    53  func (s *experimentalSuite) TestConfigureExperimentalSettingsHappy(c *C) {
    54  	for _, feature := range features.KnownFeatures() {
    55  		for _, t := range []string{"true", "false"} {
    56  			conf := &mockConf{
    57  				state: s.state,
    58  				conf:  map[string]interface{}{featureConf(feature): t},
    59  			}
    60  			err := configcore.Run(conf)
    61  			c.Check(err, IsNil)
    62  		}
    63  	}
    64  }
    65  
    66  func (s *experimentalSuite) TestExportedFeatures(c *C) {
    67  	conf := &mockConf{
    68  		state: s.state,
    69  		conf:  map[string]interface{}{featureConf(features.PerUserMountNamespace): true},
    70  	}
    71  	err := configcore.Run(conf)
    72  	c.Assert(err, IsNil)
    73  	c.Check(features.PerUserMountNamespace.ControlFile(), testutil.FilePresent)
    74  
    75  	delete(conf.changes, "experimental.per-user-mount-namespace")
    76  	err = configcore.Run(conf)
    77  	c.Assert(err, IsNil)
    78  	c.Check(features.PerUserMountNamespace.ControlFile(), testutil.FilePresent)
    79  }