-
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.
Add basic configuration object to set global channel and per repo
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package configuration | ||
|
||
import ( | ||
"fmt" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// Configuration holds the general configuration for the executable | ||
type Configuration struct { | ||
DefaultChannel string `yaml:"default_channel"` | ||
Repositories map[string]string `yaml:"repositories"` | ||
} | ||
|
||
var config Configuration | ||
|
||
// Load loads the configuration and sets it globally if loading succeeded | ||
func Load(in []byte) error { | ||
c := Configuration{} | ||
err := yaml.Unmarshal(in, &c) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse configuration: %s", err) | ||
} | ||
|
||
config = c | ||
|
||
return nil | ||
} | ||
|
||
// GetConfiguration returns the current configuration | ||
func GetConfiguration() Configuration { | ||
return config | ||
} |
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,27 @@ | ||
package configuration_test | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"gitlab.com/yakshaving.art/propaganda/configuration" | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
func TestLoadingValidConfiguration(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
b, err := ioutil.ReadFile("fixtures/valid.yml") | ||
a.NoError(err) | ||
|
||
a.NoError(configuration.Load(b)) | ||
|
||
a.EqualValues( | ||
configuration.Configuration{ | ||
DefaultChannel: "#propaganda", | ||
Repositories: map[string]string{ | ||
"pcarranza/test-webhooks": "#private_channel", | ||
}, | ||
}, | ||
configuration.GetConfiguration(), | ||
) | ||
} |
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,4 @@ | ||
--- | ||
default_channel: "#propaganda" | ||
repositories: | ||
pcarranza/test-webhooks: "#private_channel" |