Allow to use env vars in config
This commit is contained in:
parent
5e6a5e23fd
commit
2b4c6d3318
@ -10,7 +10,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
APP_NAME = "Git repository manager"
|
APP_NAME = "Git repository manager"
|
||||||
APP_DESCRIPTION = "Manage your repository with simple app"
|
APP_DESCRIPTION = "Manage your repository with simple app"
|
||||||
VERSION = "0.1"
|
VERSION = "0.1.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitRepositoryManager struct {
|
type GitRepositoryManager struct {
|
||||||
|
@ -90,5 +90,5 @@ func Example_test_sync_output() {
|
|||||||
// Output:
|
// Output:
|
||||||
// Info: Synchronizing repositories
|
// Info: Synchronizing repositories
|
||||||
// Info: All repositories are synced
|
// Info: All repositories are synced
|
||||||
// Info: Current version: 0.1
|
// Info: Current version: 0.1.1
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@ -13,6 +14,8 @@ func GetRepositoryConfig(data []byte, fileExtension string) (Configuration, erro
|
|||||||
var config Configuration
|
var config Configuration
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
data = []byte(os.ExpandEnv(string(data)))
|
||||||
|
|
||||||
switch fileExtension {
|
switch fileExtension {
|
||||||
case "yaml":
|
case "yaml":
|
||||||
err = yaml.Unmarshal(data, &config)
|
err = yaml.Unmarshal(data, &config)
|
||||||
|
@ -2,12 +2,26 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestNotSupportedFileExcension(t *testing.T) {
|
||||||
|
|
||||||
|
_, err := GetRepositoryConfig([]byte("test"), "custom")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected to get error")
|
||||||
|
}
|
||||||
|
if err.Error() != errNotSupportedType {
|
||||||
|
t.Errorf("Expected to get %v, instead of this got %v", errNotSupportedType, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetRepositoryConfigFromYaml(t *testing.T) {
|
||||||
|
|
||||||
var exampleYamlConfig = []byte(`
|
var exampleYamlConfig = []byte(`
|
||||||
workspace: /tmp
|
workspace: ${HOME}
|
||||||
repositories:
|
repositories:
|
||||||
- src: "https://github.com/example/example.git"
|
- src: "https://github.com/example/example.git"
|
||||||
dest: "example/path"
|
dest: "example/path"
|
||||||
@ -15,8 +29,10 @@ repositories:
|
|||||||
- src: https://github.com/example/example2.git
|
- src: https://github.com/example/example2.git
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
homedir, _ := os.UserHomeDir()
|
||||||
|
|
||||||
var destinationConfiguration = Configuration{
|
var destinationConfiguration = Configuration{
|
||||||
Workspace: "/tmp",
|
Workspace: homedir,
|
||||||
Repositories: []RepositoryConfig{
|
Repositories: []RepositoryConfig{
|
||||||
{
|
{
|
||||||
Name: "custom_example",
|
Name: "custom_example",
|
||||||
@ -31,18 +47,6 @@ var destinationConfiguration = Configuration{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotSupportedFileExcension(t *testing.T) {
|
|
||||||
_, err := GetRepositoryConfig(exampleYamlConfig, "custom")
|
|
||||||
if err == nil {
|
|
||||||
t.Error("Expected to get error")
|
|
||||||
}
|
|
||||||
if err.Error() != errNotSupportedType {
|
|
||||||
t.Errorf("Expected to get %v, instead of this got %v", errNotSupportedType, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetRepositoryConfigFromYaml(t *testing.T) {
|
|
||||||
|
|
||||||
result, err := GetRepositoryConfig(exampleYamlConfig, "yaml")
|
result, err := GetRepositoryConfig(exampleYamlConfig, "yaml")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user