mirror of
https://dev.azure.com/schwarzit/schwarzit.stackit-public/_git/audit-go
synced 2026-02-09 01:27:26 +00:00
Do not return plural type in GetObjectIdAndTypeFromUrlPath
This commit is contained in:
parent
965fa4e617
commit
66773aad3d
2 changed files with 6 additions and 10 deletions
|
|
@ -912,7 +912,6 @@ func OperationNameFromGrpcMethod(path string) string {
|
|||
func GetObjectIdAndTypeFromUrlPath(path string) (
|
||||
string,
|
||||
*SingularType,
|
||||
*PluralType,
|
||||
error,
|
||||
) {
|
||||
|
||||
|
|
@ -922,15 +921,15 @@ func GetObjectIdAndTypeFromUrlPath(path string) (
|
|||
objectTypePlural := AsPluralType(objectTypeIdMatches[1])
|
||||
objectTypeSingular, err := objectTypePlural.AsSingularType()
|
||||
if err != nil {
|
||||
return "", nil, nil, err
|
||||
return "", nil, err
|
||||
}
|
||||
objectType := &objectTypeSingular
|
||||
objectId := objectTypeIdMatches[2]
|
||||
|
||||
return objectId, objectType, &objectTypePlural, nil
|
||||
return objectId, objectType, nil
|
||||
}
|
||||
|
||||
return "", nil, nil, nil
|
||||
return "", nil, nil
|
||||
}
|
||||
|
||||
func ToArrayMap(input map[string]string) map[string][]string {
|
||||
|
|
|
|||
|
|
@ -978,27 +978,24 @@ func Test_OperationNameFromGrpcMethod(t *testing.T) {
|
|||
func Test_GetObjectIdAndTypeFromUrlPath(t *testing.T) {
|
||||
|
||||
t.Run("object id and type not in url", func(t *testing.T) {
|
||||
objectId, singularType, pluralType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/audit")
|
||||
objectId, singularType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/audit")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "", objectId)
|
||||
assert.Nil(t, singularType)
|
||||
assert.Nil(t, pluralType)
|
||||
})
|
||||
|
||||
t.Run("object id and type in url", func(t *testing.T) {
|
||||
objectId, singularType, pluralType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/f17d4064-9b65-4334-b6a7-8fed96340124")
|
||||
objectId, singularType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/f17d4064-9b65-4334-b6a7-8fed96340124")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "f17d4064-9b65-4334-b6a7-8fed96340124", objectId)
|
||||
assert.Equal(t, SingularTypeProject, *singularType)
|
||||
assert.Equal(t, PluralTypeProject, *pluralType)
|
||||
})
|
||||
|
||||
t.Run("multiple object ids and types in url", func(t *testing.T) {
|
||||
objectId, singularType, pluralType, err := GetObjectIdAndTypeFromUrlPath("/v2/organization/8ee58bec-d496-4bb9-af8d-72fda4d78b6b/projects/f17d4064-9b65-4334-b6a7-8fed96340124")
|
||||
objectId, singularType, err := GetObjectIdAndTypeFromUrlPath("/v2/organization/8ee58bec-d496-4bb9-af8d-72fda4d78b6b/projects/f17d4064-9b65-4334-b6a7-8fed96340124")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "f17d4064-9b65-4334-b6a7-8fed96340124", objectId)
|
||||
assert.Equal(t, SingularTypeProject, *singularType)
|
||||
assert.Equal(t, PluralTypeProject, *pluralType)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue