subhash kumar singh | 327d9db | 2021-09-30 19:07:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2021 Samsung |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | |
| 17 | This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 18 | platform project (RICP). |
| 19 | ================================================================================== |
| 20 | */ |
| 21 | package resthooks |
| 22 | |
| 23 | import ( |
| 24 | "os" |
| 25 | "testing" |
| 26 | |
| 27 | "github.com/stretchr/testify/assert" |
| 28 | "github.com/stretchr/testify/mock" |
| 29 | ) |
| 30 | |
| 31 | var rh *Resthook |
| 32 | var sdlInst *SdlMock |
| 33 | |
| 34 | func TestMain(m *testing.M) { |
| 35 | sdlInst = new(SdlMock) |
subhash kumar singh | 6017d6a | 2021-10-26 12:14:26 +0000 | [diff] [blame^] | 36 | |
| 37 | sdlInst.On("GetAll", "A1m_ns").Return([]string{"a1.policy_instance.1006001.qos", |
| 38 | "a1.policy_type.1006001", |
| 39 | "a1.policy_type.20000", |
| 40 | "a1.policy_inst_metadata.1006001.qos", |
| 41 | }, nil) |
| 42 | |
subhash kumar singh | 327d9db | 2021-09-30 19:07:18 +0000 | [diff] [blame] | 43 | rh = createResthook(sdlInst) |
| 44 | code := m.Run() |
| 45 | os.Exit(code) |
| 46 | } |
| 47 | |
| 48 | func TestGetAllPolicyType(t *testing.T) { |
| 49 | resp := rh.GetAllPolicyType() |
| 50 | assert.Equal(t, 2, len(resp)) |
| 51 | } |
| 52 | |
| 53 | type SdlMock struct { |
| 54 | mock.Mock |
| 55 | } |
| 56 | |
| 57 | func (s *SdlMock) GetAll(ns string) ([]string, error) { |
subhash kumar singh | 6017d6a | 2021-10-26 12:14:26 +0000 | [diff] [blame^] | 58 | args := s.MethodCalled("GetAll", ns) |
| 59 | return args.Get(0).([]string), nil |
subhash kumar singh | 327d9db | 2021-09-30 19:07:18 +0000 | [diff] [blame] | 60 | } |