gitee.com/quant1x/gox@v1.21.2/cron/option_test.go (about)

     1  package cron
     2  
     3  import (
     4  	"log"
     5  	"strings"
     6  	"testing"
     7  	"time"
     8  )
     9  
    10  func TestWithLocation(t *testing.T) {
    11  	c := New(WithLocation(time.UTC))
    12  	if c.location != time.UTC {
    13  		t.Errorf("expected UTC, got %v", c.location)
    14  	}
    15  }
    16  
    17  func TestWithParser(t *testing.T) {
    18  	var parser = NewParser(Dow)
    19  	c := New(WithParser(parser))
    20  	if c.parser != parser {
    21  		t.Error("expected provided parser")
    22  	}
    23  }
    24  
    25  func TestWithVerboseLogger(t *testing.T) {
    26  	var buf syncWriter
    27  	var logger = log.New(&buf, "", log.LstdFlags)
    28  	c := New(WithLogger(VerbosePrintfLogger(logger)))
    29  	if c.logger.(printfLogger).logger != logger {
    30  		t.Error("expected provided logger")
    31  	}
    32  
    33  	c.AddFunc("@every 1s", func() {})
    34  	c.Start()
    35  	time.Sleep(OneSecond)
    36  	c.Stop()
    37  	out := buf.String()
    38  	if !strings.Contains(out, "schedule,") ||
    39  		!strings.Contains(out, "run,") {
    40  		t.Error("expected to see some actions, got:", out)
    41  	}
    42  }