blob: 4725975044fc7aafa341e5f4f61a3dab5b0bdd3e [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
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 Barbarie4a2564d2018-07-26 11:02:58 -040016package model
17
18import (
William Kurkiandaa6bb22019-03-07 12:26:28 -050019 "github.com/opencord/voltha-protos/go/voltha"
Stephane Barbarie1039ec42019-02-04 10:43:16 -050020 "reflect"
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040021 "testing"
22)
23
Stephane Barbarie1039ec42019-02-04 10:43:16 -050024// Dissect a proto message by extracting all the children fields
25func TestChildType_01_Device_Proto_ChildrenFields(t *testing.T) {
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040026 var cls *voltha.Device
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040027
Stephane Barbarie1039ec42019-02-04 10:43:16 -050028 t.Logf("Extracting children fields from proto type: %s", reflect.TypeOf(cls))
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040029 names := ChildrenFields(cls)
Stephane Barbarie1039ec42019-02-04 10:43:16 -050030 t.Logf("Extracting children field names: %+v", names)
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040031
Stephane Barbarie1039ec42019-02-04 10:43:16 -050032 expectedKeys := []string{"ports", "flows", "flow_groups", "image_downloads", "pm_configs"}
33 for _, key := range expectedKeys {
34 if _, exists := names[key]; !exists {
35 t.Errorf("Missing key:%s from class type:%s", key, reflect.TypeOf(cls))
36 }
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040037 }
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040038}
39
Stephane Barbarie1039ec42019-02-04 10:43:16 -050040// Verify that the cache contains an entry for types on which ChildrenFields was performed
41func TestChildType_02_Cache_Keys(t *testing.T) {
Stephane Barbarieef6650d2019-07-18 12:15:09 -040042 if _, exists := getChildTypes().Cache[reflect.TypeOf(&voltha.Device{}).String()]; !exists {
Stephane Barbarie1039ec42019-02-04 10:43:16 -050043 t.Errorf("getChildTypeCache().Cache should have an entry of type: %+v\n", reflect.TypeOf(&voltha.Device{}).String())
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040044 }
Stephane Barbarieef6650d2019-07-18 12:15:09 -040045 for k := range getChildTypes().Cache {
Stephane Barbariedc5022d2018-11-19 15:21:44 -050046 t.Logf("getChildTypeCache().Cache Key:%+v\n", k)
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040047 }
48}