forked from distribworks/dkron
-
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.
Fix tags loading from config file (distribworks#315)
* Fix tags loading from config file Fixed tests reseting viper
- Loading branch information
Victor Castell
authored
Nov 15, 2017
1 parent
90294af
commit 4b9bdc2
Showing
3 changed files
with
54 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dkron | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/mitchellh/cli" | ||
) | ||
|
||
func TestReadConfigTags(t *testing.T) { | ||
shutdownCh := make(chan struct{}) | ||
defer close(shutdownCh) | ||
|
||
ui := new(cli.MockUi) | ||
a := &AgentCommand{ | ||
Ui: ui, | ||
ShutdownCh: shutdownCh, | ||
} | ||
|
||
viper.Reset() | ||
viper.SetConfigType("json") | ||
var jsonConfig = []byte(`{ | ||
"tags": { | ||
"foo": "bar" | ||
} | ||
}`) | ||
viper.ReadConfig(bytes.NewBuffer(jsonConfig)) | ||
config := ReadConfig(a) | ||
t.Log(config.Tags) | ||
assert.Equal(t, "bar", config.Tags["foo"]) | ||
|
||
viper.Set("tag", []string{"monthy=python"}) | ||
config = ReadConfig(a) | ||
assert.NotContains(t, config.Tags, "foo") | ||
assert.Contains(t, config.Tags, "monthy") | ||
assert.Equal(t, "python", config.Tags["monthy"]) | ||
} |
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