github.com/lyft/flytestdlib@v0.3.12-0.20210213045714-8cdd111ecda1/logger/logger_test.go (about) 1 // Defines global context-aware logger. 2 // The default implementation uses logrus. This package registers "logger" config section on init(). The structure of the 3 // config section is expected to be un-marshal-able to Config struct. 4 package logger 5 6 import ( 7 "context" 8 "reflect" 9 "testing" 10 11 "github.com/sirupsen/logrus" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func init() { 16 if err := SetConfig(&Config{ 17 Level: InfoLevel, 18 IncludeSourceCode: true, 19 }); err != nil { 20 panic(err) 21 } 22 } 23 24 func TestIsLoggable(t *testing.T) { 25 type args struct { 26 ctx context.Context 27 level Level 28 } 29 tests := []struct { 30 name string 31 args args 32 want bool 33 }{ 34 {"Debug Is not loggable", args{ctx: context.TODO(), level: DebugLevel}, false}, 35 {"Info Is loggable", args{ctx: context.TODO(), level: InfoLevel}, true}, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 if got := IsLoggable(tt.args.ctx, tt.args.level); got != tt.want { 40 t.Errorf("IsLoggable() = %v, want %v", got, tt.want) 41 } 42 }) 43 } 44 } 45 46 func TestDebug(t *testing.T) { 47 type args struct { 48 ctx context.Context 49 args []interface{} 50 } 51 tests := []struct { 52 name string 53 args args 54 }{ 55 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 56 } 57 for _, tt := range tests { 58 t.Run(tt.name, func(t *testing.T) { 59 Debug(tt.args.ctx, tt.args.args...) 60 }) 61 } 62 } 63 64 func TestPrint(t *testing.T) { 65 type args struct { 66 ctx context.Context 67 args []interface{} 68 } 69 tests := []struct { 70 name string 71 args args 72 }{ 73 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 74 } 75 for _, tt := range tests { 76 t.Run(tt.name, func(t *testing.T) { 77 Print(tt.args.ctx, tt.args.args...) 78 }) 79 } 80 } 81 82 func TestInfo(t *testing.T) { 83 type args struct { 84 ctx context.Context 85 args []interface{} 86 } 87 tests := []struct { 88 name string 89 args args 90 }{ 91 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 92 } 93 for _, tt := range tests { 94 t.Run(tt.name, func(t *testing.T) { 95 Info(tt.args.ctx, tt.args.args...) 96 }) 97 } 98 } 99 100 func TestWarn(t *testing.T) { 101 type args struct { 102 ctx context.Context 103 args []interface{} 104 } 105 tests := []struct { 106 name string 107 args args 108 }{ 109 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 110 } 111 for _, tt := range tests { 112 t.Run(tt.name, func(t *testing.T) { 113 Warn(tt.args.ctx, tt.args.args...) 114 }) 115 } 116 } 117 118 func TestWarning(t *testing.T) { 119 type args struct { 120 ctx context.Context 121 args []interface{} 122 } 123 tests := []struct { 124 name string 125 args args 126 }{ 127 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 128 } 129 for _, tt := range tests { 130 t.Run(tt.name, func(t *testing.T) { 131 Warning(tt.args.ctx, tt.args.args...) 132 }) 133 } 134 } 135 136 func TestError(t *testing.T) { 137 type args struct { 138 ctx context.Context 139 args []interface{} 140 } 141 tests := []struct { 142 name string 143 args args 144 }{ 145 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 146 } 147 for _, tt := range tests { 148 t.Run(tt.name, func(t *testing.T) { 149 Error(tt.args.ctx, tt.args.args...) 150 }) 151 } 152 } 153 154 func TestPanic(t *testing.T) { 155 type args struct { 156 ctx context.Context 157 args []interface{} 158 } 159 tests := []struct { 160 name string 161 args args 162 }{ 163 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 164 } 165 for _, tt := range tests { 166 t.Run(tt.name, func(t *testing.T) { 167 assert.Panics(t, func() { 168 Panic(tt.args.ctx, tt.args.args...) 169 }) 170 }) 171 } 172 } 173 174 func TestDebugf(t *testing.T) { 175 type args struct { 176 ctx context.Context 177 format string 178 args []interface{} 179 } 180 tests := []struct { 181 name string 182 args args 183 }{ 184 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 185 } 186 for _, tt := range tests { 187 t.Run(tt.name, func(t *testing.T) { 188 Debugf(tt.args.ctx, tt.args.format, tt.args.args...) 189 }) 190 } 191 } 192 193 func TestPrintf(t *testing.T) { 194 type args struct { 195 ctx context.Context 196 format string 197 args []interface{} 198 } 199 tests := []struct { 200 name string 201 args args 202 }{ 203 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 204 } 205 for _, tt := range tests { 206 t.Run(tt.name, func(t *testing.T) { 207 Printf(tt.args.ctx, tt.args.format, tt.args.args...) 208 }) 209 } 210 } 211 212 func TestInfof(t *testing.T) { 213 type args struct { 214 ctx context.Context 215 format string 216 args []interface{} 217 } 218 tests := []struct { 219 name string 220 args args 221 }{ 222 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 223 } 224 for _, tt := range tests { 225 t.Run(tt.name, func(t *testing.T) { 226 Infof(tt.args.ctx, tt.args.format, tt.args.args...) 227 }) 228 } 229 } 230 231 func TestInfofNoCtx(t *testing.T) { 232 type args struct { 233 format string 234 args []interface{} 235 } 236 tests := []struct { 237 name string 238 args args 239 }{ 240 {"test", args{format: "%v", args: []interface{}{"arg"}}}, 241 } 242 for _, tt := range tests { 243 t.Run(tt.name, func(t *testing.T) { 244 InfofNoCtx(tt.args.format, tt.args.args...) 245 }) 246 } 247 } 248 249 func TestWarnf(t *testing.T) { 250 type args struct { 251 ctx context.Context 252 format string 253 args []interface{} 254 } 255 tests := []struct { 256 name string 257 args args 258 }{ 259 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 260 } 261 for _, tt := range tests { 262 t.Run(tt.name, func(t *testing.T) { 263 Warnf(tt.args.ctx, tt.args.format, tt.args.args...) 264 }) 265 } 266 } 267 268 func TestWarningf(t *testing.T) { 269 type args struct { 270 ctx context.Context 271 format string 272 args []interface{} 273 } 274 tests := []struct { 275 name string 276 args args 277 }{ 278 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 279 } 280 for _, tt := range tests { 281 t.Run(tt.name, func(t *testing.T) { 282 Warningf(tt.args.ctx, tt.args.format, tt.args.args...) 283 }) 284 } 285 } 286 287 func TestErrorf(t *testing.T) { 288 type args struct { 289 ctx context.Context 290 format string 291 args []interface{} 292 } 293 tests := []struct { 294 name string 295 args args 296 }{ 297 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 298 } 299 for _, tt := range tests { 300 t.Run(tt.name, func(t *testing.T) { 301 Errorf(tt.args.ctx, tt.args.format, tt.args.args...) 302 }) 303 } 304 } 305 306 func TestPanicf(t *testing.T) { 307 type args struct { 308 ctx context.Context 309 format string 310 args []interface{} 311 } 312 tests := []struct { 313 name string 314 args args 315 }{ 316 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 317 } 318 for _, tt := range tests { 319 t.Run(tt.name, func(t *testing.T) { 320 assert.Panics(t, func() { 321 Panicf(tt.args.ctx, tt.args.format, tt.args.args...) 322 }) 323 }) 324 } 325 } 326 327 func TestDebugln(t *testing.T) { 328 type args struct { 329 ctx context.Context 330 args []interface{} 331 } 332 tests := []struct { 333 name string 334 args args 335 }{ 336 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 337 } 338 for _, tt := range tests { 339 t.Run(tt.name, func(t *testing.T) { 340 Debugln(tt.args.ctx, tt.args.args...) 341 }) 342 } 343 } 344 345 func TestPrintln(t *testing.T) { 346 type args struct { 347 ctx context.Context 348 args []interface{} 349 } 350 tests := []struct { 351 name string 352 args args 353 }{ 354 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 355 } 356 for _, tt := range tests { 357 t.Run(tt.name, func(t *testing.T) { 358 Println(tt.args.ctx, tt.args.args...) 359 }) 360 } 361 } 362 363 func TestInfoln(t *testing.T) { 364 type args struct { 365 ctx context.Context 366 args []interface{} 367 } 368 tests := []struct { 369 name string 370 args args 371 }{ 372 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 373 } 374 for _, tt := range tests { 375 t.Run(tt.name, func(t *testing.T) { 376 Infoln(tt.args.ctx, tt.args.args...) 377 }) 378 } 379 } 380 381 func TestWarnln(t *testing.T) { 382 type args struct { 383 ctx context.Context 384 args []interface{} 385 } 386 tests := []struct { 387 name string 388 args args 389 }{ 390 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 391 } 392 for _, tt := range tests { 393 t.Run(tt.name, func(t *testing.T) { 394 Warnln(tt.args.ctx, tt.args.args...) 395 }) 396 } 397 } 398 399 func TestWarningln(t *testing.T) { 400 type args struct { 401 ctx context.Context 402 args []interface{} 403 } 404 tests := []struct { 405 name string 406 args args 407 }{ 408 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 409 } 410 for _, tt := range tests { 411 t.Run(tt.name, func(t *testing.T) { 412 Warningln(tt.args.ctx, tt.args.args...) 413 }) 414 } 415 } 416 417 func TestErrorln(t *testing.T) { 418 type args struct { 419 ctx context.Context 420 args []interface{} 421 } 422 tests := []struct { 423 name string 424 args args 425 }{ 426 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 427 } 428 for _, tt := range tests { 429 t.Run(tt.name, func(t *testing.T) { 430 Errorln(tt.args.ctx, tt.args.args...) 431 }) 432 } 433 } 434 435 func TestPanicln(t *testing.T) { 436 type args struct { 437 ctx context.Context 438 args []interface{} 439 } 440 tests := []struct { 441 name string 442 args args 443 }{ 444 {"test", args{ctx: context.TODO(), args: []interface{}{"arg"}}}, 445 } 446 for _, tt := range tests { 447 t.Run(tt.name, func(t *testing.T) { 448 assert.Panics(t, func() { 449 Panicln(tt.args.ctx, tt.args.args...) 450 }) 451 }) 452 } 453 } 454 455 func Test_getLogger(t *testing.T) { 456 type args struct { 457 ctx context.Context 458 } 459 tests := []struct { 460 name string 461 args args 462 want *logrus.Entry 463 }{ 464 // TODO: Add test cases. 465 } 466 for _, tt := range tests { 467 t.Run(tt.name, func(t *testing.T) { 468 if got := getLogger(tt.args.ctx); !reflect.DeepEqual(got, tt.want) { 469 t.Errorf("getLogger() = %v, want %v", got, tt.want) 470 } 471 }) 472 } 473 } 474 475 func TestWithIndent(t *testing.T) { 476 type args struct { 477 ctx context.Context 478 additionalIndent string 479 } 480 tests := []struct { 481 name string 482 args args 483 want context.Context 484 }{ 485 // TODO: Add test cases. 486 } 487 for _, tt := range tests { 488 t.Run(tt.name, func(t *testing.T) { 489 if got := WithIndent(tt.args.ctx, tt.args.additionalIndent); !reflect.DeepEqual(got, tt.want) { 490 t.Errorf("WithIndent() = %v, want %v", got, tt.want) 491 } 492 }) 493 } 494 } 495 496 func Test_getIndent(t *testing.T) { 497 type args struct { 498 ctx context.Context 499 } 500 tests := []struct { 501 name string 502 args args 503 want string 504 }{ 505 // TODO: Add test cases. 506 } 507 for _, tt := range tests { 508 t.Run(tt.name, func(t *testing.T) { 509 if got := getIndent(tt.args.ctx); got != tt.want { 510 t.Errorf("getIndent() = %v, want %v", got, tt.want) 511 } 512 }) 513 } 514 } 515 516 func TestFatal(t *testing.T) { 517 type args struct { 518 ctx context.Context 519 args []interface{} 520 } 521 tests := []struct { 522 name string 523 args args 524 }{ 525 // TODO: Add test cases. 526 } 527 for _, tt := range tests { 528 t.Run(tt.name, func(t *testing.T) { 529 Fatal(tt.args.ctx, tt.args.args...) 530 }) 531 } 532 } 533 534 func TestFatalf(t *testing.T) { 535 type args struct { 536 ctx context.Context 537 format string 538 args []interface{} 539 } 540 tests := []struct { 541 name string 542 args args 543 }{ 544 // TODO: Add test cases. 545 } 546 for _, tt := range tests { 547 t.Run(tt.name, func(t *testing.T) { 548 Fatalf(tt.args.ctx, tt.args.format, tt.args.args...) 549 }) 550 } 551 } 552 553 func TestFatalln(t *testing.T) { 554 type args struct { 555 ctx context.Context 556 args []interface{} 557 } 558 tests := []struct { 559 name string 560 args args 561 }{ 562 // TODO: Add test cases. 563 } 564 for _, tt := range tests { 565 t.Run(tt.name, func(t *testing.T) { 566 Fatalln(tt.args.ctx, tt.args.args...) 567 }) 568 } 569 } 570 571 func Test_onConfigUpdated(t *testing.T) { 572 type args struct { 573 cfg Config 574 } 575 tests := []struct { 576 name string 577 args args 578 }{ 579 // TODO: Add test cases. 580 } 581 for _, tt := range tests { 582 t.Run(tt.name, func(t *testing.T) { 583 onConfigUpdated(tt.args.cfg) 584 }) 585 } 586 }