7752be825bc2357ffc279aaae2d3d3048ac666f0
[ric-plt/submgr.git] / pkg / teststub / testwrapper.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19 package teststub
20
21 import (
22         "fmt"
23         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
24         "strings"
25         "testing"
26 )
27
28 type TestWrapper struct {
29         *xapp.Log
30         desc string
31 }
32
33 func (tw *TestWrapper) Init(desc string) {
34         tw.desc = strings.ToUpper(desc)
35         tw.Log = xapp.NewLogger(tw.desc)
36         //tw.SetLevel(defaultLogLevel)
37 }
38
39 func (tw *TestWrapper) GetDesc() string {
40         return tw.desc
41 }
42
43 //-----------------------------------------------------------------------------
44 //
45 //-----------------------------------------------------------------------------
46 func (tw *TestWrapper) TestError(t *testing.T, pattern string, args ...interface{}) {
47         tw.Error(fmt.Sprintf(pattern, args...))
48         t.Errorf(fmt.Sprintf(pattern, args...))
49 }
50
51 //-----------------------------------------------------------------------------
52 //
53 //-----------------------------------------------------------------------------
54 func (tw *TestWrapper) TestLog(t *testing.T, pattern string, args ...interface{}) {
55         tw.Info(fmt.Sprintf(pattern, args...))
56         t.Logf(fmt.Sprintf(pattern, args...))
57 }
58
59 func NewTestWrapper(desc string) *TestWrapper {
60         tent := &TestWrapper{}
61         tent.Init(desc)
62         return tent
63 }