~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/cmd/aliasfile_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

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