blob: 74774d9b1ef674386bbc18617f5ad5c85deb3def [file] [log] [blame]
vinokuma703a70b2023-07-17 10:06:43 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "testing"
20
21 "github.com/google/gopacket/layers"
22)
23
24func TestGetMetadataForL2Protocol(t *testing.T) {
25 type args struct {
26 etherType layers.EthernetType
27 }
28 tests := []struct {
29 name string
30 args args
31 want uint8
32 wantErr bool
33 }{
34 {
35 name: "EthernetTypeDot1QDoubleTag",
36 args: args{
37 etherType: layers.EthernetTypeDot1QDoubleTag,
38 },
39 want: 2,
40 },
41 {
42 name: "EthernetTypeQinQDoubleTag",
43 args: args{
44 etherType: layers.EthernetTypeQinQDoubleTag,
45 },
46 want: 3,
47 },
48 }
49 for _, tt := range tests {
50 t.Run(tt.name, func(t *testing.T) {
51 switch tt.name {
52 case "EthernetTypeDot1QDoubleTag", "EthernetTypeQinQDoubleTag":
53 got, err := GetMetadataForL2Protocol(tt.args.etherType)
54 if (err != nil) != tt.wantErr {
55 t.Errorf("GetMetadataForL2Protocol() error = %v, wantErr %v", err, tt.wantErr)
56 return
57 }
58 if got != tt.want {
59 t.Errorf("GetMetadataForL2Protocol() = %v, want %v", got, tt.want)
60 }
61 }
62 })
63 }
64}
65
66func Test_convertToUInt64(t *testing.T) {
67 type args struct {
68 data string
69 }
70 tests := []struct {
71 name string
72 args args
73 want uint64
74 }{
75 {
76 name: "ParseUint_error",
77 args: args{
78 data: "test",
79 },
80 },
81 }
82 for _, tt := range tests {
83 t.Run(tt.name, func(t *testing.T) {
84 if got := convertToUInt64(tt.args.data); got != tt.want {
85 t.Errorf("convertToUInt64() = %v, want %v", got, tt.want)
86 }
87 })
88 }
89}