aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2017-03-05 22:01:04 +0100
committerKamil Cholewiński <harry666t@gmail.com>2017-03-05 22:01:04 +0100
commitfcc329e6ec15ea668accbb523f4a54953966b509 (patch)
tree5705a4f122ebf694e07eb5b25f47189ef4117d5f
parentddec67d1d3cf03dad92e01c4d50aa6e3b8d5eb07 (diff)
downloadjudo-fcc329e6ec15ea668accbb523f4a54953966b509.zip
judo-fcc329e6ec15ea668accbb523f4a54953966b509.tar.gz
judo-fcc329e6ec15ea668accbb523f4a54953966b509.tar.bz2
Refactor Inventory.Populate
-rw-r--r--libjudo/inventory.go8
-rw-r--r--libjudo/inventory_test.go14
-rw-r--r--main.go4
3 files changed, 12 insertions, 14 deletions
diff --git a/libjudo/inventory.go b/libjudo/inventory.go
index 95e273b..1205b51 100644
--- a/libjudo/inventory.go
+++ b/libjudo/inventory.go
@@ -11,20 +11,18 @@ import (
type Inventory struct {
hosts []*Host
- names []string
s *SeenString
}
-func NewInventory(names []string) *Inventory {
+func NewInventory() *Inventory {
return &Inventory{
hosts: []*Host{},
- names: names,
s: NewSeenString(),
}
}
-func (inventory *Inventory) Populate() {
- for _, name := range inventory.names {
+func (inventory *Inventory) Populate(names []string) {
+ for _, name := range names {
for host := range inventory.resolveNames(name) {
inventory.hosts = append(inventory.hosts, host)
}
diff --git a/libjudo/inventory_test.go b/libjudo/inventory_test.go
index 9a70f80..6921eea 100644
--- a/libjudo/inventory_test.go
+++ b/libjudo/inventory_test.go
@@ -6,7 +6,7 @@ import (
)
func TestInventory_resolveNames(t *testing.T) {
- inventory := NewInventory([]string{})
+ inventory := NewInventory()
for host := range inventory.resolveNames("test") {
if host.Name != "test" {
t.Error("no host")
@@ -16,8 +16,8 @@ func TestInventory_resolveNames(t *testing.T) {
}
func TestInventoryPopulate1(t *testing.T) {
- inventory := NewInventory([]string{"test"})
- inventory.Populate()
+ inventory := NewInventory()
+ inventory.Populate([]string{"test"})
host, ok := <-inventory.GetHosts()
if !ok {
t.Error("no host")
@@ -30,8 +30,8 @@ func TestInventoryPopulate1(t *testing.T) {
}
func TestInventoryPopulate2(t *testing.T) {
- inventory := NewInventory([]string{"test1", "test2"})
- inventory.Populate()
+ inventory := NewInventory()
+ inventory.Populate([]string{"test1", "test2"})
seen := make(map[string]bool)
for host := range inventory.GetHosts() {
@@ -46,8 +46,8 @@ func TestInventoryPopulate2(t *testing.T) {
}
func TestExpandHostGroups_NoDuplicates(t *testing.T) {
- inventory := NewInventory([]string{"test1", "test2", "test1"})
- inventory.Populate()
+ inventory := NewInventory()
+ inventory.Populate([]string{"test1", "test2", "test1"})
seen := make(map[string]bool)
for host := range inventory.GetHosts() {
diff --git a/main.go b/main.go
index f83e8bc..a2ef118 100644
--- a/main.go
+++ b/main.go
@@ -65,8 +65,8 @@ func ParseArgs(args []string) (
return nil, usage, 111, nil
}
- inventory := libjudo.NewInventory(args)
- inventory.Populate()
+ inventory := libjudo.NewInventory()
+ inventory.Populate(args)
job = libjudo.NewJob(inventory, script, command, timeout)
return job, "", 0, nil