Merge "Improve validation for invoker management"
authorHenrik Andersson <henrik.b.andersson@est.tech>
Tue, 31 Jan 2023 12:22:02 +0000 (12:22 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Tue, 31 Jan 2023 12:22:02 +0000 (12:22 +0000)
capifcore/internal/providermanagementapi/typevalidation.go
capifcore/internal/providermanagementapi/typevalidation_test.go

index 1b2e582..c873f30 100644 (file)
@@ -34,12 +34,15 @@ func (ri RegistrationInformation) Validate() error {
 }
 
 func (fd APIProviderFunctionDetails) Validate() error {
+       if len(strings.TrimSpace(string(fd.ApiProvFuncRole))) == 0 {
+               return errors.New("APIProviderFunctionDetails missing required apiProvFuncRole")
+       }
        switch role := fd.ApiProvFuncRole; role {
        case ApiProviderFuncRoleAEF:
        case ApiProviderFuncRoleAPF:
        case ApiProviderFuncRoleAMF:
        default:
-               return errors.New("APIProviderFunctionDetails missing required apiProvFuncRole")
+               return errors.New("APIProviderFunctionDetails has invalid apiProvFuncRole")
        }
 
        return fd.RegInfo.Validate()
index 3980b19..7698aab 100644 (file)
@@ -59,6 +59,14 @@ func TestValidateAPIProviderFunctionDetails(t *testing.T) {
                assert.Contains(t, err.Error(), "apiProvFuncRole")
        }
 
+       var invalidFuncRole ApiProviderFuncRole = "invalid"
+       funcDetailsUnderTest.ApiProvFuncRole = invalidFuncRole
+       err = funcDetailsUnderTest.Validate()
+       if assert.Error(t, err) {
+               assert.Contains(t, err.Error(), "invalid")
+               assert.Contains(t, err.Error(), "apiProvFuncRole")
+       }
+
        funcDetailsUnderTest.ApiProvFuncRole = ApiProviderFuncRoleAEF
        err = funcDetailsUnderTest.Validate()
        if assert.Error(t, err) {