generated from ekristen/go-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/ekristen/distillery/pkg/common" | ||
) | ||
|
||
type Aliases map[string]*Alias | ||
|
||
type Alias struct { | ||
Name string `yaml:"name" toml:"name"` | ||
Version string `yaml:"version" toml:"version"` | ||
Bin string `yaml:"bin" toml:"bin"` | ||
} | ||
|
||
func (a *Alias) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
var value string | ||
if unmarshal(&value) == nil { | ||
p := strings.Split(value, "@") | ||
a.Name = p[0] | ||
a.Version = common.Latest | ||
if len(p) > 1 { | ||
a.Version = p[1] | ||
} | ||
return nil | ||
} | ||
|
||
type alias Alias | ||
aux := (*alias)(a) | ||
if err := unmarshal(aux); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *Alias) UnmarshalText(b []byte) error { | ||
*a = Alias{ | ||
Name: string(b), | ||
Version: "latest", | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfigNewYAML(t *testing.T) { | ||
cfg, err := New("testdata/base.yaml") | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "/home/test/.distillery", cfg.Path) | ||
assert.Equal(t, "/home/test/.cache", cfg.CachePath) | ||
|
||
aliases := &Aliases{ | ||
"dist": &Alias{ | ||
Name: "ekristen/distillery", | ||
Version: "latest", | ||
}, | ||
"aws-nuke": &Alias{ | ||
Name: "ekristen/aws-nuke", | ||
Version: "3.29.3", | ||
}, | ||
} | ||
|
||
assert.EqualValues(t, aliases, cfg.Aliases) | ||
} | ||
|
||
func TestConfigNewTOML(t *testing.T) { | ||
cfg, err := New("testdata/base.toml") | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "/home/test/.distillery", cfg.Path) | ||
assert.Equal(t, "/home/test/.cache", cfg.CachePath) | ||
|
||
aliases := &Aliases{ | ||
"dist": &Alias{ | ||
Name: "ekristen/distillery", | ||
Version: "latest", | ||
}, | ||
"aws-nuke": &Alias{ | ||
Name: "ekristen/aws-nuke", | ||
Version: "3.29.3", | ||
}, | ||
} | ||
|
||
assert.EqualValues(t, aliases, cfg.Aliases) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
path = "/home/test/.distillery" | ||
cache_path = "/home/test/.cache" | ||
|
||
[aliases] | ||
dist = "ekristen/distillery" | ||
|
||
[aliases.aws-nuke] | ||
name = "ekristen/aws-nuke" | ||
version = "3.29.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
path: /home/test/.distillery | ||
cache_path: /home/test/.cache | ||
aliases: | ||
dist: ekristen/distillery | ||
aws-nuke: | ||
name: ekristen/aws-nuke | ||
version: 3.29.3 |