github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/bootloader/androidbootenv/androidbootenv_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 androidbootenv_test 21 22 import ( 23 "path/filepath" 24 "testing" 25 26 . "gopkg.in/check.v1" 27 28 "github.com/snapcore/snapd/bootloader/androidbootenv" 29 ) 30 31 // Hook up check.v1 into the "go test" runner 32 func Test(t *testing.T) { TestingT(t) } 33 34 type androidbootenvTestSuite struct { 35 envPath string 36 env *androidbootenv.Env 37 } 38 39 var _ = Suite(&androidbootenvTestSuite{}) 40 41 func (a *androidbootenvTestSuite) SetUpTest(c *C) { 42 a.envPath = filepath.Join(c.MkDir(), "androidbootenv") 43 a.env = androidbootenv.NewEnv(a.envPath) 44 c.Assert(a.env, NotNil) 45 } 46 47 func (a *androidbootenvTestSuite) TestSet(c *C) { 48 a.env.Set("key", "value") 49 c.Check(a.env.Get("key"), Equals, "value") 50 } 51 52 func (a *androidbootenvTestSuite) TestSaveAndLoad(c *C) { 53 a.env.Set("key1", "value1") 54 a.env.Set("key2", "") 55 a.env.Set("key3", "value3") 56 57 err := a.env.Save() 58 c.Assert(err, IsNil) 59 60 env2 := androidbootenv.NewEnv(a.envPath) 61 c.Check(env2, NotNil) 62 63 err = env2.Load() 64 c.Assert(err, IsNil) 65 66 c.Assert(env2.Get("key1"), Equals, "value1") 67 c.Assert(env2.Get("key2"), Equals, "") 68 c.Assert(env2.Get("key3"), Equals, "value3") 69 }