-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add OptionFlagSlice, refactor, remove duplicated code
- Loading branch information
Showing
11 changed files
with
79 additions
and
88 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
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,36 @@ | ||
package config | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOptions(t *testing.T) { | ||
for _, opt := range Options { | ||
kind := reflect.TypeOf(opt.T()).Kind() | ||
if kind == reflect.Slice && !opt.HasFlags(OptionFlagSlice) { | ||
t.Errorf("option %s is a slice but does not have the slice flag", opt.GetName()) | ||
} | ||
if kind != reflect.Slice && opt.HasFlags(OptionFlagSlice) { | ||
t.Errorf("option %s is not a slice but has the slice flag", opt.GetName()) | ||
} | ||
if opt.HasFlags(OptionFlagPFlag | OptionFlagSensitive) { | ||
t.Errorf("%s: sensitive options shouldn't have pflags", opt.GetName()) | ||
} | ||
} | ||
} | ||
|
||
func TestOption_HasFlags(t *testing.T) { | ||
opt := &Option[any]{Flags: OptionFlagSensitive | OptionFlagPFlag | OptionFlagSlice} | ||
assert.True(t, opt.HasFlags(OptionFlagSensitive)) | ||
assert.True(t, opt.HasFlags(OptionFlagPFlag)) | ||
assert.True(t, opt.HasFlags(OptionFlagSlice)) | ||
assert.True(t, opt.HasFlags(OptionFlagSensitive|OptionFlagPFlag)) | ||
assert.True(t, opt.HasFlags(OptionFlagSensitive|OptionFlagSlice)) | ||
assert.True(t, opt.HasFlags(OptionFlagPFlag|OptionFlagSlice)) | ||
assert.True(t, opt.HasFlags(OptionFlagSensitive|OptionFlagPFlag|OptionFlagSlice)) | ||
assert.False(t, opt.HasFlags(OptionFlagConfig)) | ||
assert.False(t, opt.HasFlags(OptionFlagConfig|OptionFlagSensitive)) | ||
} |
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