Adding needed files for ci-management
[nonrtric/rapp/ransliceassurance.git] / smoversion / messages / stdVesMessage_test.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2021: Nordix Foundation
6 //   %%
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
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
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===================================
19 //
20
21 package messages
22
23 import (
24         "testing"
25
26         "github.com/stretchr/testify/require"
27 )
28
29 func TestGetMeasurements(t *testing.T) {
30         assertions := require.New(t)
31         type fields struct {
32                 Event Event
33         }
34         tests := []struct {
35                 name   string
36                 fields fields
37                 want   []Measurement
38         }{
39                 {
40                         name: "get measurements message",
41                         fields: fields{
42                                 Event: Event{
43                                         CommonEventHeader: CommonEventHeader{
44                                                 Domain:               "stndDefined",
45                                                 StndDefinedNamespace: "o-ran-sc-du-hello-world-pm-streaming-oas3",
46                                         },
47                                         StndDefinedFields: StndDefinedFields{
48                                                 StndDefinedFieldsVersion: "1.0",
49                                                 SchemaReference:          "https://gerrit.o-ran-sc.org/r/gitweb?p=scp/oam/modeling.git;a=blob_plain;f=data-model/oas3/experimental/o-ran-sc-du-hello-world-oas3.json;hb=refs/heads/master",
50                                                 Data: Data{
51                                                         DataId: "id",
52                                                         Measurements: []Measurement{{
53                                                                 MeasurementTypeInstanceReference: "/o-ran-sc-du-hello-world:network-function/distributed-unit-functions[id='O-DU-1211']/cell[id='cell-1']/supported-measurements[performance-measurement-type='user-equipment-average-throughput-uplink']/supported-snssai-subcounter-instances[slice-differentiator='1'][slice-service-type='1']",
54                                                                 Value:                            51232,
55                                                                 Unit:                             "kbit/s",
56                                                         }},
57                                                 },
58                                         },
59                                 },
60                         },
61                         want: []Measurement{{
62                                 MeasurementTypeInstanceReference: "/o-ran-sc-du-hello-world:network-function/distributed-unit-functions[id='O-DU-1211']/cell[id='cell-1']/supported-measurements[performance-measurement-type='user-equipment-average-throughput-uplink']/supported-snssai-subcounter-instances[slice-differentiator='1'][slice-service-type='1']",
63                                 Value:                            51232,
64                                 Unit:                             "kbit/s",
65                         }},
66                 },
67         }
68
69         for _, tt := range tests {
70                 t.Run(tt.name, func(t *testing.T) {
71                         message := StdDefinedMessage{
72                                 Event: tt.fields.Event,
73                         }
74                         var got []Measurement
75                         if got = message.GetMeasurements(); len(got) != len(tt.want) {
76                                 t.Errorf("Message.GetMeasurements() = %v, want %v", got, tt.want)
77                         }
78
79                         for _, meas := range got {
80                                 assertions.Equal(51232, meas.Value)
81                                 assertions.Contains(meas.MeasurementTypeInstanceReference, "user-equipment-average-throughput-uplink")
82                         }
83
84                 })
85         }
86 }