github.com/argoproj/argo-cd/v3@v3.2.1/test/fixture/path/hack_path.go (about)

     1  package path
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  type AddBinDirToPath struct {
    13  	originalPath string
    14  }
    15  
    16  func (h AddBinDirToPath) Close() {
    17  	_ = os.Setenv("PATH", h.originalPath)
    18  }
    19  
    20  // add the hack path which has the argocd binary
    21  func NewBinDirToPath(t *testing.T) AddBinDirToPath {
    22  	t.Helper()
    23  	originalPath := os.Getenv("PATH")
    24  	binDir, err := filepath.Abs("../../dist")
    25  	require.NoError(t, err)
    26  	t.Setenv("PATH", fmt.Sprintf("%s:%s", originalPath, binDir))
    27  	return AddBinDirToPath{originalPath}
    28  }