github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/overlord/configstate/configcore/users_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 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 . "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/overlord/configstate/configcore" 26 ) 27 28 type usersSuite struct { 29 configcoreSuite 30 } 31 32 var _ = Suite(&usersSuite{}) 33 34 func (s *usersSuite) TestUsersCreateAutomaticEarly(c *C) { 35 patch := map[string]interface{}{ 36 "users.create.automatic": "false", 37 } 38 tr := &mockConf{state: s.state} 39 err := configcore.Early(classicDev, tr, patch) 40 c.Assert(err, IsNil) 41 42 c.Check(tr.conf, DeepEquals, map[string]interface{}{ 43 "users.create.automatic": false, 44 }) 45 } 46 47 func (s *usersSuite) TestUsersCreateAutomaticInvalid(c *C) { 48 err := configcore.Run(classicDev, &mockConf{ 49 state: s.state, 50 conf: map[string]interface{}{"users.create.automatic": "foo"}, 51 }) 52 c.Assert(err, ErrorMatches, `users.create.automatic can only be set to 'true' or 'false'`) 53 } 54 55 func (s *usersSuite) TestUsersCreateAutomaticConfigure(c *C) { 56 tests := []struct { 57 value interface{} 58 expected bool 59 }{ 60 {"true", true}, 61 {"false", false}, 62 {true, true}, 63 {false, false}, 64 } 65 66 for _, t := range tests { 67 conf := &mockConf{ 68 state: s.state, 69 conf: map[string]interface{}{"users.create.automatic": t.value}, 70 } 71 72 err := configcore.Run(classicDev, conf) 73 c.Assert(err, IsNil) 74 75 c.Check(conf.conf["users.create.automatic"], Equals, t.expected) 76 } 77 }