mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
normalize enums to lowercase with hyphens (#2363)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
parent
4ee6be3777
commit
4d0da703bf
@ -7,11 +7,11 @@ type Scope string
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// UnknownScope is the default scope
|
// UnknownScope is the default scope
|
||||||
UnknownScope Scope = "UnknownScope"
|
UnknownScope Scope = "unknown-scope"
|
||||||
// SquashedScope indicates to only catalog content visible from the squashed filesystem representation (what can be seen only within the container at runtime)
|
// SquashedScope indicates to only catalog content visible from the squashed filesystem representation (what can be seen only within the container at runtime)
|
||||||
SquashedScope Scope = "Squashed"
|
SquashedScope Scope = "squashed"
|
||||||
// AllLayersScope indicates to catalog content on all layers, regardless if it is visible from the container at runtime.
|
// AllLayersScope indicates to catalog content on all layers, regardless if it is visible from the container at runtime.
|
||||||
AllLayersScope Scope = "AllLayers"
|
AllLayersScope Scope = "all-layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AllScopes is a slice containing all possible scope options
|
// AllScopes is a slice containing all possible scope options
|
||||||
@ -23,9 +23,9 @@ var AllScopes = []Scope{
|
|||||||
// ParseScope returns a scope as indicated from the given string.
|
// ParseScope returns a scope as indicated from the given string.
|
||||||
func ParseScope(userStr string) Scope {
|
func ParseScope(userStr string) Scope {
|
||||||
switch strings.ToLower(userStr) {
|
switch strings.ToLower(userStr) {
|
||||||
case strings.ToLower(SquashedScope.String()):
|
case SquashedScope.String():
|
||||||
return SquashedScope
|
return SquashedScope
|
||||||
case "all-layers", strings.ToLower(AllLayersScope.String()):
|
case "alllayers", AllLayersScope.String():
|
||||||
return AllLayersScope
|
return AllLayersScope
|
||||||
}
|
}
|
||||||
return UnknownScope
|
return UnknownScope
|
||||||
|
|||||||
57
syft/source/scope_test.go
Normal file
57
syft/source/scope_test.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseScope(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
want Scope
|
||||||
|
}{
|
||||||
|
// go cases
|
||||||
|
{
|
||||||
|
name: "squashed",
|
||||||
|
want: SquashedScope,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "all-layers",
|
||||||
|
want: AllLayersScope,
|
||||||
|
},
|
||||||
|
// fall back to unknown
|
||||||
|
{
|
||||||
|
name: "make-believe",
|
||||||
|
want: UnknownScope,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
want: UnknownScope,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: " ",
|
||||||
|
want: UnknownScope,
|
||||||
|
},
|
||||||
|
// to support the original value
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "Squashed",
|
||||||
|
want: SquashedScope,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "AllLayers",
|
||||||
|
want: AllLayersScope,
|
||||||
|
},
|
||||||
|
// case insensitive
|
||||||
|
{
|
||||||
|
name: "alLlaYerS",
|
||||||
|
want: AllLayersScope,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
assert.Equal(t, tt.want, ParseScope(tt.name))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user