-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can read/write output flag to config file * ensures values are valid * fix analytics-opt-out in config file to work with multiple definitions of boolean
- Loading branch information
Showing
5 changed files
with
154 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package config_test | ||
|
||
import ( | ||
"fmt" | ||
"ldcli/internal/config" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewConfig(t *testing.T) { | ||
t.Run("analytics-opt-out", func(t *testing.T) { | ||
tests := map[string]struct { | ||
expected bool | ||
input interface{} | ||
}{ | ||
"when value is true": { | ||
expected: true, | ||
input: true, | ||
}, | ||
"when value is 1": { | ||
expected: true, | ||
input: 1, | ||
}, | ||
"when value is false": { | ||
expected: false, | ||
input: false, | ||
}, | ||
"when value is 0": { | ||
expected: false, | ||
input: 0, | ||
}, | ||
} | ||
for name, tt := range tests { | ||
tt := tt | ||
t.Run(fmt.Sprintf("%s is %t", name, tt.expected), func(t *testing.T) { | ||
rawConfig := map[string]interface{}{ | ||
"analytics-opt-out": tt.input, | ||
} | ||
|
||
configFile, err := config.NewConfig(rawConfig) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, tt.expected, *configFile.AnalyticsOptOut) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("is an error when analytics-opt-out is something else", func(t *testing.T) { | ||
rawConfig := map[string]interface{}{ | ||
"analytics-opt-out": "something", | ||
} | ||
|
||
_, err := config.NewConfig(rawConfig) | ||
|
||
assert.EqualError(t, err, "analytics-opt-out must be true or false") | ||
}) | ||
|
||
t.Run("analytics-opt-out", func(t *testing.T) { | ||
tests := map[string]struct { | ||
input string | ||
}{ | ||
"is valid when value is json": { | ||
input: "json", | ||
}, | ||
"is valid when value is plaintext": { | ||
input: "json", | ||
}, | ||
} | ||
for name, tt := range tests { | ||
tt := tt | ||
t.Run(name, func(t *testing.T) { | ||
rawConfig := map[string]interface{}{ | ||
"output": tt.input, | ||
} | ||
|
||
configFile, err := config.NewConfig(rawConfig) | ||
|
||
require.NoError(t, err) | ||
assert.Equal(t, tt.input, configFile.Output) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("is invalid with an invalid output", func(t *testing.T) { | ||
rawConfig := map[string]interface{}{ | ||
"output": "invalid", | ||
} | ||
|
||
_, err := config.NewConfig(rawConfig) | ||
|
||
assert.EqualError(t, err, "output is invalid") | ||
}) | ||
} |
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