test: increase unit test coverage

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-08-30 01:25:57 +02:00
parent 6a80df85c8
commit 69f7414f29
7 changed files with 170 additions and 69 deletions
+20 -19
View File
@@ -57,47 +57,48 @@ func (u BackendURL) MarshalText() ([]byte, error) {
return []byte(s), nil
}
type OutputFormat int
type OutputFormat string
const (
OutputFormatJSON OutputFormat = iota
OutputFormatLogger
OutputFormatHuman
OutputFormatJSON OutputFormat = "json"
OutputFormatLogger OutputFormat = "logger"
OutputFormatHuman OutputFormat = "human"
)
var (
OutputFormatNames = []string{"json", "logger", "human"}
OutputFormats = []OutputFormat{
OutputFormatJSON,
OutputFormatLogger,
OutputFormatHuman,
}
)
func (f *OutputFormat) UnmarshalText(text []byte) error {
for i, of := range OutputFormatNames {
if of == string(text) {
*f = OutputFormat(i)
return nil
}
*f = OutputFormat(text)
switch *f {
case OutputFormatJSON:
case OutputFormatLogger:
case OutputFormatHuman:
return nil
}
return fmt.Errorf("unknown output format: %s", string(text))
}
func (f OutputFormat) MarshalText() ([]byte, error) {
return []byte(OutputFormatNames[int(f)]), nil
return []byte(f), nil
}
func (f OutputFormat) String() string {
b, err := f.MarshalText()
if err != nil {
panic(fmt.Errorf("failed marshal: %w", err))
}
return string(b)
return string(f)
}
func (f OutputFormat) Set(str string) error {
func (f *OutputFormat) Set(str string) error {
return f.UnmarshalText([]byte(str))
}
func (f OutputFormat) Type() string {
func (f *OutputFormat) Type() string {
return "string"
}