github.com/matrixorigin/matrixone@v1.2.0/pkg/logutil/adapt_cron_test.go (about)

     1  // Copyright 2022 Matrix Origin
     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 logutil
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/common/moerr"
    22  )
    23  
    24  func TestCronLogger_Error(t *testing.T) {
    25  	type fields struct {
    26  		logInfo bool
    27  	}
    28  	type args struct {
    29  		err           error
    30  		msg           string
    31  		keysAndValues []any
    32  	}
    33  	tests := []struct {
    34  		name   string
    35  		fields fields
    36  		args   args
    37  	}{
    38  		{
    39  			name: "normal",
    40  			fields: fields{
    41  				logInfo: false,
    42  			},
    43  			args: args{
    44  				err:           moerr.NewInternalError(context.TODO(), "test"),
    45  				msg:           "hello world",
    46  				keysAndValues: []any{"int", 1, "key", "val"},
    47  			},
    48  		},
    49  		{
    50  			name: "no_error",
    51  			fields: fields{
    52  				logInfo: true,
    53  			},
    54  			args: args{
    55  				err:           nil,
    56  				msg:           "hello world",
    57  				keysAndValues: []any{"int", 1, "key", "val"},
    58  			},
    59  		},
    60  	}
    61  	for _, tt := range tests {
    62  		t.Run(tt.name, func(t *testing.T) {
    63  			l := GetCronLogger(tt.fields.logInfo)
    64  			l.Error(tt.args.err, tt.args.msg, tt.args.keysAndValues...)
    65  		})
    66  	}
    67  }
    68  
    69  func TestCronLogger_Info(t *testing.T) {
    70  	type fields struct {
    71  		logInfo bool
    72  	}
    73  	type args struct {
    74  		msg           string
    75  		keysAndValues []any
    76  	}
    77  	tests := []struct {
    78  		name   string
    79  		fields fields
    80  		args   args
    81  	}{
    82  		{
    83  			name: "normal",
    84  			fields: fields{
    85  				logInfo: true,
    86  			},
    87  			args: args{
    88  				msg:           "hello world",
    89  				keysAndValues: []any{"int", 1, "key", "val"},
    90  			},
    91  		},
    92  		{
    93  			name: "disable",
    94  			fields: fields{
    95  				logInfo: false,
    96  			},
    97  			args: args{
    98  				msg:           "hello world",
    99  				keysAndValues: []any{"int", 1, "key", "val"},
   100  			},
   101  		},
   102  		{
   103  			name: "empty_kv",
   104  			fields: fields{
   105  				logInfo: true,
   106  			},
   107  			args: args{
   108  				msg:           "hello world",
   109  				keysAndValues: []any{},
   110  			},
   111  		},
   112  	}
   113  	for _, tt := range tests {
   114  		t.Run(tt.name, func(t *testing.T) {
   115  			l := GetCronLogger(tt.fields.logInfo)
   116  			l.Info(tt.args.msg, tt.args.keysAndValues...)
   117  		})
   118  	}
   119  }