Move actions, resource (types), and scopes to packages. (#149)
This commit is contained in:
1 parent
9d1d0ba08e
commit
d8f11af4d7
37 files changed
+721
-460
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package scope
|
||||
|
||||
// Type defines the possible types for Scopes
|
||||
type Type uint32
|
||||
|
||||
const (
|
||||
Unknown Type = 0
|
||||
Organization Type = 1
|
||||
Project Type = 2
|
||||
)
|
||||
|
||||
func (s Type) String() string {
|
||||
return [...]string{
|
||||
"unknown",
|
||||
"organization",
|
||||
"project",
|
||||
}[s]
|
||||
}
|
||||
|
||||
func (s Type) Prefix() string {
|
||||
return [...]string{
|
||||
"unknown",
|
||||
"o",
|
||||
"p",
|
||||
}[s]
|
||||
}
|
||||
|
||||
func StringToScopeType(s string) Type {
|
||||
switch s {
|
||||
case Organization.String():
|
||||
return Organization
|
||||
case Project.String():
|
||||
return Project
|
||||
default:
|
||||
return Unknown
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package scope
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_StringToScopeType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s string
|
||||
want Type
|
||||
wantPrefix string
|
||||
}{
|
||||
{
|
||||
name: "org",
|
||||
s: "organization",
|
||||
want: Organization,
|
||||
wantPrefix: "o",
|
||||
},
|
||||
{
|
||||
name: "proj",
|
||||
s: "project",
|
||||
want: Project,
|
||||
wantPrefix: "p",
|
||||
},
|
||||
{
|
||||
name: "unknown",
|
||||
s: "org",
|
||||
want: Unknown,
|
||||
wantPrefix: "unknown",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
got := StringToScopeType(tt.s)
|
||||
assert.Equal(tt.want, got)
|
||||
assert.Equalf(tt.wantPrefix, got.Prefix(), "unexpected prefix for %s", tt.s)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user