khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "fmt" |
| 20 | "github.com/opencord/voltha/protos/go/voltha" |
| 21 | "reflect" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | /* |
| 26 | |
| 27 | */ |
| 28 | func Test_ChildType_01_CacheIsEmpty(t *testing.T) { |
| 29 | if GetInstance().ChildrenFieldsCache != nil || len(GetInstance().ChildrenFieldsCache) > 0 { |
| 30 | t.Errorf("GetInstance().ChildrenFieldsCache should be empty: %+v\n", GetInstance().ChildrenFieldsCache) |
| 31 | } |
| 32 | t.Logf("GetInstance().ChildrenFieldsCache is empty - %+v\n", GetInstance().ChildrenFieldsCache) |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | |
| 37 | */ |
| 38 | func Test_ChildType_02_Device_Proto_ChildrenFields(t *testing.T) { |
| 39 | |
| 40 | var cls *voltha.Device |
| 41 | //cls = &voltha.Device{Id:"testing-Config-rev-id"} |
| 42 | |
| 43 | names := ChildrenFields(cls) |
| 44 | |
| 45 | tst := reflect.ValueOf(cls).Elem().FieldByName("ImageDownloads") |
| 46 | |
| 47 | fmt.Printf("############ Field by name : %+v\n", reflect.TypeOf(tst.Interface())) |
| 48 | |
| 49 | if names == nil || len(names) == 0 { |
| 50 | t.Errorf("ChildrenFields failed to return names: %+v\n", names) |
| 51 | } |
| 52 | t.Logf("ChildrenFields returned names: %+v\n", names) |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | |
| 57 | */ |
| 58 | func Test_ChildType_03_CacheHasOneEntry(t *testing.T) { |
| 59 | if GetInstance().ChildrenFieldsCache == nil || len(GetInstance().ChildrenFieldsCache) != 1 { |
| 60 | t.Errorf("GetInstance().ChildrenFieldsCache should have one entry: %+v\n", GetInstance().ChildrenFieldsCache) |
| 61 | } |
| 62 | t.Logf("GetInstance().ChildrenFieldsCache has one entry: %+v\n", GetInstance().ChildrenFieldsCache) |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | |
| 67 | */ |
| 68 | func Test_ChildType_04_ChildrenFieldsCache_Keys(t *testing.T) { |
| 69 | for k := range GetInstance().ChildrenFieldsCache { |
| 70 | t.Logf("GetInstance().ChildrenFieldsCache Key:%+v\n", k) |
| 71 | } |
| 72 | } |