env_test.go 667 B

12345678910111213141516171819202122232425262728293031323334
  1. package proc
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestEnv(t *testing.T) {
  8. assert.True(t, len(Env("any")) == 0)
  9. envLock.RLock()
  10. val, ok := envs["any"]
  11. envLock.RUnlock()
  12. assert.True(t, len(val) == 0)
  13. assert.True(t, ok)
  14. assert.True(t, len(Env("any")) == 0)
  15. }
  16. func TestEnvInt(t *testing.T) {
  17. val, ok := EnvInt("any")
  18. assert.Equal(t, 0, val)
  19. assert.False(t, ok)
  20. err := os.Setenv("anyInt", "10")
  21. assert.Nil(t, err)
  22. val, ok = EnvInt("anyInt")
  23. assert.Equal(t, 10, val)
  24. assert.True(t, ok)
  25. err = os.Setenv("anyString", "a")
  26. assert.Nil(t, err)
  27. val, ok = EnvInt("anyString")
  28. assert.Equal(t, 0, val)
  29. assert.False(t, ok)
  30. }