github.com/jmigpin/editor@v1.6.0/util/osutil/env_test.go (about)

     1  //go:build !windows
     2  
     3  package osutil
     4  
     5  import (
     6  	"testing"
     7  )
     8  
     9  func TestEnv1(t *testing.T) {
    10  	env := []string{"AA=1", "BB=2"}
    11  	env = SetEnv(env, "CC", "3")
    12  	if GetEnv(env, "AA") != "1" {
    13  		t.Fail()
    14  	}
    15  	if GetEnv(env, "CC") != "3" {
    16  		t.Fail()
    17  	}
    18  }
    19  
    20  func TestEnv2(t *testing.T) {
    21  	env := []string{"AA=1", "BB=2"}
    22  	env = SetEnv(env, "AA", "3")
    23  	if GetEnv(env, "AA") != "3" {
    24  		t.Fail()
    25  	}
    26  	if GetEnv(env, "BB") != "2" {
    27  		t.Fail()
    28  	}
    29  	if GetEnv(env, "CC") != "" {
    30  		t.Fail()
    31  	}
    32  }
    33  
    34  func TestEnv3(t *testing.T) {
    35  	env := []string{"AA=1", "AA=2"}
    36  	if GetEnv(env, "AA") != "1" {
    37  		t.Fail()
    38  	}
    39  }
    40  
    41  func TestEnv4(t *testing.T) {
    42  	env := []string{"AA=1", "AA=2"}
    43  	env = SetEnv(env, "AA", "3")
    44  	if len(env) != 1 {
    45  		t.Fail()
    46  	}
    47  }