github.com/cidverse/cid-sdk-go@v0.0.0-20240318001225-c193d83f053e/env-tag_test.go (about)

     1  package cidsdk
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  type EnvOverwriteStruct struct {
    11  	Key   string `env:"KEY"`
    12  	Value string `env:"VALUE"`
    13  }
    14  
    15  func TestEnvOverwrite(t *testing.T) {
    16  	os.Clearenv()
    17  	val := EnvOverwriteStruct{Key: "hello", Value: "world"}
    18  	_ = os.Setenv("KEY", "hi")
    19  	_ = os.Setenv("VALUE", "mom")
    20  	OverwriteFromEnv(&val)
    21  
    22  	assert.Equal(t, "hi", val.Key)
    23  	assert.Equal(t, "mom", val.Value)
    24  }