-
Notifications
You must be signed in to change notification settings - Fork 32
/
aliasfile_test.go
58 lines (48 loc) · 1.29 KB
/
aliasfile_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2015 Canonical Ltd.
// Licensed under the LGPLv3, see LICENSE file for details.
package cmd_test
import (
_ "fmt"
"io/ioutil"
"path/filepath"
"github.com/juju/testing"
gc "gopkg.in/check.v1"
"github.com/juju/cmd/v4"
)
type ParseAliasFileSuite struct {
testing.LoggingSuite
}
var _ = gc.Suite(&ParseAliasFileSuite{})
func (*ParseAliasFileSuite) TestMissing(c *gc.C) {
dir := c.MkDir()
filename := filepath.Join(dir, "missing")
aliases := cmd.ParseAliasFile(filename)
c.Assert(aliases, gc.NotNil)
c.Assert(aliases, gc.HasLen, 0)
}
func (*ParseAliasFileSuite) TestParse(c *gc.C) {
dir := c.MkDir()
filename := filepath.Join(dir, "missing")
content := `
# comments skipped, as are the blank lines, such as the line
# at the start of this file
foo = trailing-space
repeat = first
flags = flags --with flag
# if the same alias name is used more than once, last one wins
repeat = second
# badly formated values are logged, but skipped
no equals sign
=
key =
= value
`
err := ioutil.WriteFile(filename, []byte(content), 0644)
c.Assert(err, gc.IsNil)
aliases := cmd.ParseAliasFile(filename)
c.Assert(aliases, gc.DeepEquals, map[string][]string{
"foo": []string{"trailing-space"},
"repeat": []string{"second"},
"flags": []string{"flags", "--with", "flag"},
})
}