Files
argo-cd/util/io/paths_test.go
Michael Crenshaw 1dd2821631 feat: collect and log hydration commands (#19346)
* feat: collect and log hydration commands

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fix tests

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* don't actually log for now

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* add helm test, handle random values file path

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fix test

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* simplify; only return commands on success; only return helm template command, not helm dependency

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* kustomize test

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* only return commands on success, to match Helm

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fix import order

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* simplify, since we're not collecting non-template Helm commands

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* lint

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fixes from comments

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
2024-08-09 16:06:58 +00:00

64 lines
1.7 KiB
Go

package io
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetPath_SameURLs(t *testing.T) {
paths := NewRandomizedTempPaths(os.TempDir())
res1, err := paths.GetPath("https://localhost/test.txt")
require.NoError(t, err)
res2, err := paths.GetPath("https://localhost/test.txt")
require.NoError(t, err)
assert.Equal(t, res1, res2)
}
func TestGetPath_DifferentURLs(t *testing.T) {
paths := NewRandomizedTempPaths(os.TempDir())
res1, err := paths.GetPath("https://localhost/test1.txt")
require.NoError(t, err)
res2, err := paths.GetPath("https://localhost/test2.txt")
require.NoError(t, err)
assert.NotEqual(t, res1, res2)
}
func TestGetPath_SameURLsDifferentInstances(t *testing.T) {
paths1 := NewRandomizedTempPaths(os.TempDir())
res1, err := paths1.GetPath("https://localhost/test.txt")
require.NoError(t, err)
paths2 := NewRandomizedTempPaths(os.TempDir())
res2, err := paths2.GetPath("https://localhost/test.txt")
require.NoError(t, err)
assert.NotEqual(t, res1, res2)
}
func TestGetPathIfExists(t *testing.T) {
paths := NewRandomizedTempPaths(os.TempDir())
t.Run("does not exist", func(t *testing.T) {
path := paths.GetPathIfExists("https://localhost/test.txt")
assert.Empty(t, path)
})
t.Run("does exist", func(t *testing.T) {
_, err := paths.GetPath("https://localhost/test.txt")
require.NoError(t, err)
path := paths.GetPathIfExists("https://localhost/test.txt")
assert.NotEmpty(t, path)
})
}
func TestGetPaths_no_race(t *testing.T) {
paths := NewRandomizedTempPaths(os.TempDir())
go func() {
path, err := paths.GetPath("https://localhost/test.txt")
require.NoError(t, err)
assert.NotEmpty(t, path)
}()
go func() {
paths.GetPaths()
}()
}