vinokuma | f7605fc | 2023-06-02 18:08:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023-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 | |
| 16 | package onosnbi |
| 17 | |
| 18 | import ( |
| 19 | "net/http" |
| 20 | "net/http/httptest" |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | func TestDeviceHandle_ServeHTTP(t *testing.T) { |
| 25 | req, err := http.NewRequest("GET", "/serve_http/", nil) |
| 26 | if err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | |
| 30 | req.Header.Set("Content-Type", "application/json") |
| 31 | rr := httptest.NewRecorder() |
| 32 | |
| 33 | type args struct { |
| 34 | w http.ResponseWriter |
| 35 | r *http.Request |
| 36 | } |
| 37 | tests := []struct { |
| 38 | name string |
| 39 | args args |
| 40 | }{ |
| 41 | { |
| 42 | name: "DeviceHandle_ServeHTTP", |
| 43 | args: args{ |
| 44 | w: rr, |
| 45 | r: req, |
| 46 | }, |
| 47 | }, |
| 48 | } |
| 49 | for _, tt := range tests { |
| 50 | t.Run(tt.name, func(t *testing.T) { |
| 51 | dh := &DeviceHandle{} |
| 52 | dh.ServeHTTP(tt.args.w, tt.args.r) |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestDevicePortHandle_ServeHTTP(t *testing.T) { |
| 58 | req, err := http.NewRequest("GET", "/serve_http/", nil) |
| 59 | if err != nil { |
| 60 | t.Fatal(err) |
| 61 | } |
| 62 | |
| 63 | req.Header.Set("Content-Type", "application/json") |
| 64 | rr := httptest.NewRecorder() |
| 65 | |
| 66 | type args struct { |
| 67 | w http.ResponseWriter |
| 68 | r *http.Request |
| 69 | } |
| 70 | tests := []struct { |
| 71 | name string |
| 72 | args args |
| 73 | }{ |
| 74 | { |
| 75 | name: "DevicePortHandle_ServeHTTP", |
| 76 | args: args{ |
| 77 | w: rr, |
| 78 | r: req, |
| 79 | }, |
| 80 | }, |
| 81 | } |
| 82 | for _, tt := range tests { |
| 83 | t.Run(tt.name, func(t *testing.T) { |
| 84 | dh := &DevicePortHandle{} |
| 85 | dh.ServeHTTP(tt.args.w, tt.args.r) |
| 86 | }) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | func TestDevicePortHandle_ServeHTTPWithDeviceID(t *testing.T) { |
| 91 | req, err := http.NewRequest("GET", "/serve_http/", nil) |
| 92 | if err != nil { |
| 93 | t.Fatal(err) |
| 94 | } |
| 95 | |
| 96 | req.Header.Set("Content-Type", "application/json") |
| 97 | rr := httptest.NewRecorder() |
| 98 | |
| 99 | type args struct { |
| 100 | w http.ResponseWriter |
| 101 | r *http.Request |
| 102 | } |
| 103 | tests := []struct { |
| 104 | name string |
| 105 | args args |
| 106 | }{ |
| 107 | { |
| 108 | name: "DevicePortHandle_ServeHTTPWithDeviceID", |
| 109 | args: args{ |
| 110 | w: rr, |
| 111 | r: req, |
| 112 | }, |
| 113 | }, |
| 114 | } |
| 115 | for _, tt := range tests { |
| 116 | t.Run(tt.name, func(t *testing.T) { |
| 117 | dh := &DevicePortHandle{} |
| 118 | dh.ServeHTTPWithDeviceID(tt.args.w, tt.args.r) |
| 119 | }) |
| 120 | } |
| 121 | } |