github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/cmd/snap-update-ns/xdg_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 main_test 21 22 import ( 23 "bytes" 24 "strings" 25 26 . "gopkg.in/check.v1" 27 28 update "github.com/snapcore/snapd/cmd/snap-update-ns" 29 "github.com/snapcore/snapd/osutil" 30 ) 31 32 type xdgSuite struct{} 33 34 var _ = Suite(&xdgSuite{}) 35 36 func (s *xdgSuite) TestXdgRuntimeDir(c *C) { 37 c.Check(update.XdgRuntimeDir(1234), Equals, "/run/user/1234") 38 } 39 40 func (s *xdgSuite) TestExpandPrefixVariable(c *C) { 41 c.Check(update.ExpandPrefixVariable("$FOO", "$FOO", "/foo"), Equals, "/foo") 42 c.Check(update.ExpandPrefixVariable("$FOO/", "$FOO", "/foo"), Equals, "/foo/") 43 c.Check(update.ExpandPrefixVariable("$FOO/bar", "$FOO", "/foo"), Equals, "/foo/bar") 44 c.Check(update.ExpandPrefixVariable("$FOObar", "$FOO", "/foo"), Equals, "$FOObar") 45 } 46 47 func (s *xdgSuite) TestExpandXdgRuntimeDir(c *C) { 48 input := "$XDG_RUNTIME_DIR/doc/by-app/snap.foo $XDG_RUNTIME_DIR/doc none bind,rw 0 0\n" 49 output := "/run/user/1234/doc/by-app/snap.foo /run/user/1234/doc none bind,rw 0 0\n" 50 profile, err := osutil.ReadMountProfile(strings.NewReader(input)) 51 c.Assert(err, IsNil) 52 update.ExpandXdgRuntimeDir(profile, 1234) 53 builder := &bytes.Buffer{} 54 profile.WriteTo(builder) 55 c.Check(builder.String(), Equals, output) 56 }