...

Source file src/github.com/thlib/go-timezone-local/tzlocal/tz_windows_test.go

Documentation: github.com/thlib/go-timezone-local/tzlocal

     1  package tzlocal
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestMappings(t *testing.T) {
     9  	// sanity check: can we find all IANA names from WinTZtoIANA in IANAtoWinTZ?
    10  	for _, v := range WinTZtoIANA {
    11  		if _, ok := IANAtoWinTZ[v]; !ok {
    12  			t.Errorf("could not find IANA name %v in IANAtoWinTZ", v)
    13  		}
    14  	}
    15  	// sanity checks: can we find all IANA names from IANAtoWinTZ in WinTZtoIANA?
    16  	// can we successfully call time.LoadLocation(tzname) for all given IANA names?
    17  	for k, v := range IANAtoWinTZ {
    18  		if _, ok := WinTZtoIANA[v]; !ok {
    19  			t.Errorf("could not find Win tz name %v in WinTZtoIANA", v)
    20  		}
    21  		if _, err := time.LoadLocation(k); err != nil {
    22  			t.Errorf("time.LoadLocation failed for IANA tz name %v", k)
    23  		}
    24  	}
    25  }
    26  
    27  func TestLocalTZ(t *testing.T) {
    28  	s, err := localTZfromTzutil()
    29  	if err != nil {
    30  		t.Errorf("got unexpected error %v", err)
    31  	}
    32  	if s == "" {
    33  		t.Error("got unexpected empty result with no error")
    34  	}
    35  
    36  	s, err = localTZfromReg()
    37  	if err != nil {
    38  		t.Errorf("got unexpected error %v", err)
    39  	}
    40  	if s == "" {
    41  		t.Error("got unexpected empty result with no error")
    42  	}
    43  
    44  	s, err = LocalTZ()
    45  	if err != nil {
    46  		t.Errorf("got unexpected error %v", err)
    47  	}
    48  	if s == "" {
    49  		t.Error("got unexpected empty result with no error")
    50  	}
    51  
    52  	tmp := WinTZtoIANA
    53  	WinTZtoIANA = map[string]string{}
    54  	s, err = LocalTZ()
    55  	if err == nil {
    56  		t.Error("expected error but got nil")
    57  	}
    58  	if s != "" {
    59  		t.Errorf("expected empty result but got %v", s)
    60  	}
    61  	WinTZtoIANA = tmp
    62  }
    63  

View as plain text