Akash Soni | d36d23b | 2023-08-18 12:51:40 +0530 | [diff] [blame^] | 1 | /* |
| 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 | |
| 16 | package onosnbi |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "net/http" |
| 21 | "net/http/httptest" |
| 22 | "testing" |
| 23 | app "voltha-go-controller/internal/pkg/controller" |
| 24 | "voltha-go-controller/internal/test/mocks" |
| 25 | |
| 26 | "github.com/golang/mock/gomock" |
| 27 | "github.com/gorilla/mux" |
| 28 | ) |
| 29 | |
| 30 | func TestMetersHandle_GetMeter(t *testing.T) { |
| 31 | type args struct { |
| 32 | cntx context.Context |
| 33 | meterID string |
| 34 | w http.ResponseWriter |
| 35 | r *http.Request |
| 36 | } |
| 37 | req, err := http.NewRequest("GET", "/vgc/v1/meters/", nil) |
| 38 | if err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | vars := map[string]string{ |
| 42 | "id": "1234", |
| 43 | } |
| 44 | req = mux.SetURLVars(req, vars) |
| 45 | req.Header.Set("Content-Type", "application/json") |
| 46 | rr := httptest.NewRecorder() |
| 47 | metersHandle := &MetersHandle{} |
| 48 | appMock := mocks.NewMockApp(gomock.NewController(t)) |
| 49 | app.NewController(ctx, appMock) |
| 50 | tests := []struct { |
| 51 | name string |
| 52 | mh *MetersHandle |
| 53 | args args |
| 54 | }{ |
| 55 | { |
| 56 | name: "Get_Meters", |
| 57 | mh: metersHandle, |
| 58 | args: args{ |
| 59 | cntx: context.Background(), |
| 60 | meterID: "1234", |
| 61 | w: rr, |
| 62 | r: req, |
| 63 | }, |
| 64 | }, |
| 65 | } |
| 66 | for _, tt := range tests { |
| 67 | t.Run(tt.name, func(t *testing.T) { |
| 68 | mh := &MetersHandle{} |
| 69 | mh.GetMeter(tt.args.cntx, tt.args.meterID, tt.args.w, tt.args.r) |
| 70 | }) |
| 71 | } |
| 72 | } |