github.com/gogf/gf@v1.16.9/os/glog/glog_z_unit_basic_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package glog
     8  
     9  import (
    10  	"bytes"
    11  	"github.com/gogf/gf/test/gtest"
    12  	"github.com/gogf/gf/text/gstr"
    13  	"testing"
    14  )
    15  
    16  func Test_Print(t *testing.T) {
    17  	gtest.C(t, func(t *gtest.T) {
    18  		w := bytes.NewBuffer(nil)
    19  		l := NewWithWriter(w)
    20  		l.Print(1, 2, 3)
    21  		l.Println(1, 2, 3)
    22  		l.Printf("%d %d %d", 1, 2, 3)
    23  		t.Assert(gstr.Count(w.String(), "["), 0)
    24  		t.Assert(gstr.Count(w.String(), "1 2 3"), 3)
    25  	})
    26  }
    27  
    28  func Test_Debug(t *testing.T) {
    29  	gtest.C(t, func(t *gtest.T) {
    30  		w := bytes.NewBuffer(nil)
    31  		l := NewWithWriter(w)
    32  		l.Debug(1, 2, 3)
    33  		l.Debugf("%d %d %d", 1, 2, 3)
    34  		t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_DEBU]), 2)
    35  		t.Assert(gstr.Count(w.String(), "1 2 3"), 2)
    36  	})
    37  }
    38  
    39  func Test_Info(t *testing.T) {
    40  	gtest.C(t, func(t *gtest.T) {
    41  		w := bytes.NewBuffer(nil)
    42  		l := NewWithWriter(w)
    43  		l.Info(1, 2, 3)
    44  		l.Infof("%d %d %d", 1, 2, 3)
    45  		t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_INFO]), 2)
    46  		t.Assert(gstr.Count(w.String(), "1 2 3"), 2)
    47  	})
    48  }
    49  
    50  func Test_Notice(t *testing.T) {
    51  	gtest.C(t, func(t *gtest.T) {
    52  		w := bytes.NewBuffer(nil)
    53  		l := NewWithWriter(w)
    54  		l.Notice(1, 2, 3)
    55  		l.Noticef("%d %d %d", 1, 2, 3)
    56  		t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_NOTI]), 2)
    57  		t.Assert(gstr.Count(w.String(), "1 2 3"), 2)
    58  	})
    59  }
    60  
    61  func Test_Warning(t *testing.T) {
    62  	gtest.C(t, func(t *gtest.T) {
    63  		w := bytes.NewBuffer(nil)
    64  		l := NewWithWriter(w)
    65  		l.Warning(1, 2, 3)
    66  		l.Warningf("%d %d %d", 1, 2, 3)
    67  		t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_WARN]), 2)
    68  		t.Assert(gstr.Count(w.String(), "1 2 3"), 2)
    69  	})
    70  }
    71  
    72  func Test_Error(t *testing.T) {
    73  	gtest.C(t, func(t *gtest.T) {
    74  		w := bytes.NewBuffer(nil)
    75  		l := NewWithWriter(w)
    76  		l.Error(1, 2, 3)
    77  		l.Errorf("%d %d %d", 1, 2, 3)
    78  		t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_ERRO]), 2)
    79  		t.Assert(gstr.Count(w.String(), "1 2 3"), 2)
    80  	})
    81  }