1
0
mirror of https://github.com/containers/buildah.git synced 2026-02-05 09:45:38 +01:00
Files
buildah/util/util_test.go
Nalin Dahyabhai ac7c018095 Suppress "meaningless package name" warnings for public APIs
Supporess "meaningless package name" warnings for exported APIs which we
know are being used by our API consumers, so that we don't break them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2025-11-13 16:05:36 -05:00

117 lines
2.2 KiB
Go

package util //nolint:revive,nolintlint
import (
"os"
"strconv"
"testing"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"go.podman.io/common/pkg/config"
)
func TestMergeEnv(t *testing.T) {
t.Parallel()
tests := [][3][]string{
{
[]string{"A=B", "B=C", "C=D"},
nil,
[]string{"A=B", "B=C", "C=D"},
},
{
nil,
[]string{"A=B", "B=C", "C=D"},
[]string{"A=B", "B=C", "C=D"},
},
{
[]string{"A=B", "B=C", "C=D", "E=F"},
[]string{"B=O", "F=G"},
[]string{"A=B", "B=O", "C=D", "E=F", "F=G"},
},
}
for i, test := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
result := MergeEnv(test[0], test[1])
if len(result) != len(test[2]) {
t.Fatalf("expected %v, got %v", test[2], result)
}
for i := range result {
if result[i] != test[2][i] {
t.Fatalf("expected %v, got %v", test[2], result)
}
}
})
}
}
func TestRuntime(t *testing.T) {
t.Parallel()
os.Setenv("CONTAINERS_CONF", "/dev/null")
conf, _ := config.Default()
defaultRuntime := conf.Engine.OCIRuntime
runtime := Runtime()
if runtime != defaultRuntime {
t.Fatalf("expected %v, got %v", runtime, defaultRuntime)
}
defaultRuntime = "myoci"
os.Setenv("BUILDAH_RUNTIME", defaultRuntime)
runtime = Runtime()
if runtime != defaultRuntime {
t.Fatalf("expected %v, got %v", runtime, defaultRuntime)
}
}
func TestMountsSort(t *testing.T) {
t.Parallel()
mounts1a := []specs.Mount{
{
Source: "/a/bb/c",
Destination: "/a/bb/c",
},
{
Source: "/a/b/c",
Destination: "/a/b/c",
},
{
Source: "/a",
Destination: "/a",
},
{
Source: "/a/b",
Destination: "/a/b",
},
{
Source: "/d/e",
Destination: "/a/c",
},
{
Source: "/b",
Destination: "/b",
},
{
Source: "/",
Destination: "/",
},
{
Source: "/a/b/c",
Destination: "/aa/b/c",
},
}
mounts1b := []string{
"/",
"/a",
"/b",
"/a/b",
"/a/c",
"/a/b/c",
"/a/bb/c",
"/aa/b/c",
}
sorted := SortMounts(mounts1a)
sortedDests := make([]string, len(mounts1a))
for i := range sorted {
sortedDests[i] = sorted[i].Destination
}
assert.Equalf(t, mounts1b, sortedDests, "sort returned results in unexpected by-destination order")
}