2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
21 package providermanagementapi
26 "github.com/stretchr/testify/assert"
29 func TestPrepareNewProvider(t *testing.T) {
30 domainInfo := "domain info"
31 funcInfo := "func info"
32 providerUnderTest := APIProviderEnrolmentDetails{
33 ApiProvDomInfo: &domainInfo,
34 ApiProvFuncs: &[]APIProviderFunctionDetails{
36 ApiProvFuncRole: ApiProviderFuncRoleAPF,
37 ApiProvFuncInfo: &funcInfo,
40 ApiProvFuncRole: ApiProviderFuncRoleAEF,
44 uuidFunc = func() string {
48 providerUnderTest.PrepareNewProvider()
50 assert.Equal(t, "domain_id_domain_info", *providerUnderTest.ApiProvDomId)
51 assert.Equal(t, "APF_id_func_info", *(*providerUnderTest.ApiProvFuncs)[0].ApiProvFuncId)
52 assert.Equal(t, "AEF_id_1", *(*providerUnderTest.ApiProvFuncs)[1].ApiProvFuncId)
54 providerUnderTest = APIProviderEnrolmentDetails{}
56 providerUnderTest.PrepareNewProvider()
58 assert.Equal(t, "domain_id_1", *providerUnderTest.ApiProvDomId)
61 func TestUpdateFuncs(t *testing.T) {
62 registeredProvider := getProvider()
64 funcInfo := "func info"
65 updatedFuncs := []APIProviderFunctionDetails{
66 (*registeredProvider.ApiProvFuncs)[0],
67 (*registeredProvider.ApiProvFuncs)[2],
69 ApiProvFuncRole: ApiProviderFuncRoleAEF,
70 ApiProvFuncInfo: &funcInfo,
73 providerUnderTest := APIProviderEnrolmentDetails{
74 ApiProvFuncs: &updatedFuncs,
76 err := providerUnderTest.UpdateFuncs(registeredProvider)
79 assert.Len(t, *providerUnderTest.ApiProvFuncs, 3)
80 assert.Equal(t, funcIdAPF, *(*providerUnderTest.ApiProvFuncs)[0].ApiProvFuncId)
81 assert.Equal(t, funcIdAEF, *(*providerUnderTest.ApiProvFuncs)[1].ApiProvFuncId)
82 assert.Equal(t, "AEF_id_func_info", *(*providerUnderTest.ApiProvFuncs)[2].ApiProvFuncId)