Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from commitdev/registry-constant-order
registry to retain order of declaration
- Loading branch information
Showing
6 changed files
with
109 additions
and
44 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
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,43 @@ | ||
package registry | ||
|
||
type Registry []Stack | ||
type Stack struct { | ||
Name string | ||
ModuleSources []string | ||
} | ||
|
||
func GetRegistry() Registry { | ||
return Registry{ | ||
// TODO: better place to store these options as configuration file or any source | ||
{ | ||
"EKS + Go + React", | ||
[]string{ | ||
"github.com/commitdev/zero-aws-eks-stack", | ||
"github.com/commitdev/zero-deployable-backend", | ||
"github.com/commitdev/zero-deployable-react-frontend", | ||
}, | ||
}, | ||
{ | ||
"Custom", []string{}, | ||
}, | ||
} | ||
} | ||
|
||
func GetModulesByName(registry Registry, name string) []string { | ||
for _, v := range registry { | ||
if v.Name == name { | ||
return v.ModuleSources | ||
} | ||
} | ||
return []string{} | ||
} | ||
|
||
func AvailableLabels(registry Registry) []string { | ||
labels := make([]string, len(registry)) | ||
i := 0 | ||
for _, stack := range registry { | ||
labels[i] = stack.Name | ||
i++ | ||
} | ||
return labels | ||
} |
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,47 @@ | ||
package registry_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/commitdev/zero/internal/registry" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAvailableLabels(t *testing.T) { | ||
reg := testRegistry() | ||
|
||
t.Run("should be same order as declared", func(t *testing.T) { | ||
labels := registry.AvailableLabels(reg) | ||
assert.Equal(t, labels, []string{ | ||
"EKS + Go + React", | ||
"foo", | ||
"bar", | ||
"lorem", | ||
"ipsum", | ||
"Custom", | ||
}) | ||
}) | ||
} | ||
|
||
func TestGetModulesByName(t *testing.T) { | ||
reg := testRegistry() | ||
t.Run("should return modules of specified stack", func(t *testing.T) { | ||
|
||
assert.Equal(t, registry.GetModulesByName(reg, "EKS + Go + React"), | ||
[]string{"module-source 1", "module-source 2"}) | ||
assert.Equal(t, registry.GetModulesByName(reg, "lorem"), []string{"module-source 5"}) | ||
assert.Equal(t, registry.GetModulesByName(reg, "ipsum"), []string{"module-source 6"}) | ||
assert.Equal(t, registry.GetModulesByName(reg, "Custom"), []string{"module-source 7"}) | ||
}) | ||
} | ||
|
||
func testRegistry() registry.Registry { | ||
return registry.Registry{ | ||
{"EKS + Go + React", []string{"module-source 1", "module-source 2"}}, | ||
{"foo", []string{"module-source 3"}}, | ||
{"bar", []string{"module-source 4"}}, | ||
{"lorem", []string{"module-source 5"}}, | ||
{"ipsum", []string{"module-source 6"}}, | ||
{"Custom", []string{"module-source 7"}}, | ||
} | ||
} |