container: add a check to ensure auth file path is always set
We never want an empty path but always force a specific auth file location, even if the location does not actually exist, due to the peculiarities mentioned in the comment of the `container.GetDefaultAuthFile` function.
This commit is contained in:
parent
e38e7c717d
commit
e290502a1d
1 changed files with 39 additions and 0 deletions
|
|
@ -2,6 +2,9 @@ package container_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -63,3 +66,39 @@ func TestClientResolve(t *testing.T) {
|
|||
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestClientAuthFilePath(t *testing.T) {
|
||||
|
||||
client, err := container.NewClient("quay.io/osbuild/osbuild")
|
||||
assert.NoError(t, err)
|
||||
|
||||
authFilePath := client.GetAuthFilePath()
|
||||
assert.NotEmpty(t, authFilePath)
|
||||
assert.Equal(t, authFilePath, container.GetDefaultAuthFile())
|
||||
|
||||
// make sure the file is accessible
|
||||
_, err = ioutil.ReadFile(authFilePath)
|
||||
assert.True(t, err == nil || os.IsNotExist(err))
|
||||
|
||||
t.Run("XDG_RUNTIME_DIR", func(t *testing.T) {
|
||||
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
||||
|
||||
if runtimeDir == "" {
|
||||
t.Skip("XDG_RUNTIME_DIR not set, skipping test")
|
||||
return
|
||||
}
|
||||
|
||||
t.Cleanup(func() {
|
||||
os.Setenv("XDG_RUNTIME_DIR", runtimeDir)
|
||||
})
|
||||
|
||||
os.Unsetenv("XDG_RUNTIME_DIR")
|
||||
|
||||
authFilePath := container.GetDefaultAuthFile()
|
||||
fmt.Printf("auth file path: %s", authFilePath)
|
||||
assert.NotEmpty(t, authFilePath)
|
||||
_, err = ioutil.ReadFile(authFilePath)
|
||||
assert.True(t, err == nil || os.IsNotExist(err))
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue