Add test for bad entries in storage.conf

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2021-06-30 10:23:21 -04:00
parent 6e19a22428
commit c2bc7b1643
No known key found for this signature in database
GPG Key ID: A2DF901DABE2C028
2 changed files with 32 additions and 0 deletions

View File

@ -1,11 +1,14 @@
package types
import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"github.com/sirupsen/logrus"
"gotest.tools/assert"
)
@ -110,3 +113,14 @@ func TestGetRootlessStorageOpts2(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, storageOpts.GraphRoot, expectedPath)
}
func TestReloadConfigurationFile(t *testing.T) {
content := bytes.NewBufferString("")
logrus.SetOutput(content)
var storageOpts StoreOptions
ReloadConfigurationFile("./storage_broken.conf", &storageOpts)
assert.Equal(t, storageOpts.RunRoot, "/run/containers/test")
logrus.SetOutput(os.Stderr)
assert.Equal(t, strings.Contains(content.String(), "Failed to decode the keys [\\\"foo\\\" \\\"storage.options.graphroot\\\"] from \\\"./storage_broken.conf\\\".\""), true)
}

18
types/storage_broken.conf Normal file
View File

@ -0,0 +1,18 @@
# This file is is a TEST configuration file for all tools
# that use the containers/storage library.
# See man 5 containers-storage.conf for more information
# The "container storage" table contains all of the server options.
foo = "bar"
[storage]
# Default Storage Driver
driver = ""
# Temporary storage location
runroot = "/run/containers/test"
[storage.options]
# Primary Read/Write location of container storage
graphroot = "/var/lib/containers/storage"