github.com/supragya/TendermintConnector@v0.0.0-20210619045051-113e32b84fb1/_deprecated_chains/cosmos/libs/common/os_test.go (about)

     1  package common
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  func TestGoPath(t *testing.T) {
     9  	// restore original gopath upon exit
    10  	path := os.Getenv("GOPATH")
    11  	defer func() {
    12  		_ = os.Setenv("GOPATH", path)
    13  	}()
    14  
    15  	err := os.Setenv("GOPATH", "~/testgopath")
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  	path = GoPath()
    20  	if path != "~/testgopath" {
    21  		t.Fatalf("should get GOPATH env var value, got %v", path)
    22  	}
    23  	os.Unsetenv("GOPATH")
    24  
    25  	path = GoPath()
    26  	if path != "~/testgopath" {
    27  		t.Fatalf("subsequent calls should return the same value, got %v", path)
    28  	}
    29  }
    30  
    31  func TestGoPathWithoutEnvVar(t *testing.T) {
    32  	// restore original gopath upon exit
    33  	path := os.Getenv("GOPATH")
    34  	defer func() {
    35  		_ = os.Setenv("GOPATH", path)
    36  	}()
    37  
    38  	os.Unsetenv("GOPATH")
    39  	// reset cache
    40  	gopath = ""
    41  
    42  	path = GoPath()
    43  	if path == "" || path == "~/testgopath" {
    44  		t.Fatalf("should get nonempty result of calling go env GOPATH, got %v", path)
    45  	}
    46  }