github.com/zhongdalu/gf@v1.0.0/g/os/genv/genv_test.go (about)

     1  package genv_test
     2  
     3  import (
     4  	"github.com/zhongdalu/gf/g/os/genv"
     5  	"github.com/zhongdalu/gf/g/test/gtest"
     6  	"os"
     7  	"testing"
     8  )
     9  
    10  func Test_Genv_All(t *testing.T) {
    11  	gtest.Case(t, func() {
    12  		gtest.Assert(os.Environ(), genv.All())
    13  	})
    14  }
    15  
    16  func Test_Genv_Get(t *testing.T) {
    17  	gtest.Case(t, func() {
    18  		key := "TEST_GET_ENV"
    19  		err := os.Setenv(key, "TEST")
    20  		gtest.Assert(err, nil)
    21  		gtest.AssertEQ(genv.Get(key), "TEST")
    22  	})
    23  }
    24  
    25  func Test_Genv_Set(t *testing.T) {
    26  	gtest.Case(t, func() {
    27  		key := "TEST_SET_ENV"
    28  		err := genv.Set(key, "TEST")
    29  		gtest.Assert(err, nil)
    30  		gtest.AssertEQ(os.Getenv(key), "TEST")
    31  	})
    32  }
    33  
    34  func Test_Genv_Remove(t *testing.T) {
    35  	gtest.Case(t, func() {
    36  		key := "TEST_REMOVE_ENV"
    37  		err := os.Setenv(key, "TEST")
    38  		gtest.Assert(err, nil)
    39  		err = genv.Remove(key)
    40  		gtest.Assert(err, nil)
    41  		gtest.AssertEQ(os.Getenv(key), "")
    42  	})
    43  }