|
| 1 | +// Copyright (c) 2021 The BFE Authors. |
| 2 | +// |
| 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 | +package bfe_module |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/baidu/go-lib/web-monitor/web_monitor" |
| 19 | + "github.com/stretchr/testify/assert" |
| 20 | + "testing" |
| 21 | +) |
| 22 | + |
| 23 | +//mock module |
| 24 | +type testModule struct { |
| 25 | +} |
| 26 | + |
| 27 | +func (tm testModule) Name() string { |
| 28 | + return "tm" |
| 29 | +} |
| 30 | + |
| 31 | +func (tm testModule) Init(cbs *BfeCallbacks, whs *web_monitor.WebHandlers, cr string) error { |
| 32 | + return nil |
| 33 | +} |
| 34 | + |
| 35 | +var tm testModule |
| 36 | + |
| 37 | +func init() { |
| 38 | + AddModule(tm) |
| 39 | +} |
| 40 | + |
| 41 | +func TestNewBfeModules(t *testing.T) { |
| 42 | + bms := NewBfeModules() |
| 43 | + assert.NotNil(t, bms) |
| 44 | +} |
| 45 | + |
| 46 | +func TestBfeModulesRegisterModule(t *testing.T) { |
| 47 | + bms := NewBfeModules() |
| 48 | + assert.NotNil(t, bms) |
| 49 | + var err error |
| 50 | + err = bms.RegisterModule("") |
| 51 | + assert.Error(t, err) |
| 52 | + |
| 53 | + err = bms.RegisterModule("tm") |
| 54 | + assert.NoError(t, err) |
| 55 | +} |
| 56 | + |
| 57 | +func TestBfeModulesGetModule(t *testing.T) { |
| 58 | + bms := NewBfeModules() |
| 59 | + assert.NotNil(t, bms) |
| 60 | + err := bms.RegisterModule("tm") |
| 61 | + assert.NoError(t, err) |
| 62 | + |
| 63 | + bm := bms.GetModule("tm") |
| 64 | + assert.NotNil(t, bm) |
| 65 | +} |
| 66 | + |
| 67 | +func TestBfeModulesInit(t *testing.T) { |
| 68 | + bms := NewBfeModules() |
| 69 | + assert.NotNil(t, bms) |
| 70 | + var err error |
| 71 | + err = bms.RegisterModule("tm") |
| 72 | + assert.Nil(t, err) |
| 73 | + |
| 74 | + err = bms.Init(nil, nil, "") |
| 75 | + assert.Nil(t, err) |
| 76 | +} |
| 77 | + |
| 78 | +func TestModConfPath(t *testing.T) { |
| 79 | + s := ModConfPath("/home/bfe/conf", "mod_access") |
| 80 | + assert.EqualValues(t, "/home/bfe/conf/mod_access/mod_access.conf", s) |
| 81 | +} |
| 82 | + |
| 83 | +func TestModConfDir(t *testing.T) { |
| 84 | + s := ModConfDir("/home/bfe/conf", "mod_access") |
| 85 | + assert.EqualValues(t, "/home/bfe/conf/mod_access", s) |
| 86 | +} |
| 87 | + |
| 88 | +func TestModuleStatusGetJSON(t *testing.T) { |
| 89 | + var err error |
| 90 | + TestBfeModulesInit(t) |
| 91 | + _, err = ModuleStatusGetJSON() |
| 92 | + assert.NoError(t, err) |
| 93 | +} |
0 commit comments