github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/logger/log_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package logger
     5  
     6  import (
     7  	"sync"
     8  	"testing"
     9  
    10  	logging "github.com/keybase/go-logging"
    11  )
    12  
    13  // This test must pass with -race.
    14  func TestInitLogging(t *testing.T) {
    15  	var l1, l2 *Standard
    16  
    17  	var wg sync.WaitGroup
    18  	wg.Add(2)
    19  
    20  	// New must be race-free.
    21  	go func() {
    22  		defer wg.Done()
    23  		l1 = New("l1")
    24  		_ = l1
    25  	}()
    26  	go func() {
    27  		defer wg.Done()
    28  		l2 = New("l2")
    29  		_ = l2
    30  	}()
    31  
    32  	wg.Wait()
    33  
    34  	// New must also initialize the level correctly.
    35  	l1Level := logging.GetLevel("l1")
    36  	if l1Level != logging.INFO {
    37  		t.Errorf("l1 level=%s is unexpectedly not INFO", l1Level)
    38  	}
    39  	l2Level := logging.GetLevel("l2")
    40  	if l2Level != logging.INFO {
    41  		t.Errorf("l2 level=%s is unexpectedly not INFO", l2Level)
    42  	}
    43  }