aboutsummaryrefslogtreecommitdiff
path: root/libkpod/config_test.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-01 14:38:21 -0400
committerGitHub <noreply@github.com>2017-11-01 14:38:21 -0400
commitf5019df3f5da9030ce21e5c8ad3d3921a6585e7f (patch)
tree05412dcc190ca026dbe51a4ef72bb91ff646e7c6 /libkpod/config_test.go
parent2b74391cd5281f6fdf391ff8ad50fd1490f6bf89 (diff)
parenteab0737f1189a7b88f0a37a6b894ca4345b6853f (diff)
downloadpodman-f5019df3f5da9030ce21e5c8ad3d3921a6585e7f.tar.gz
podman-f5019df3f5da9030ce21e5c8ad3d3921a6585e7f.tar.bz2
podman-f5019df3f5da9030ce21e5c8ad3d3921a6585e7f.zip
Merge pull request #1 from mheon/master
Initial checkin
Diffstat (limited to 'libkpod/config_test.go')
-rw-r--r--libkpod/config_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/libkpod/config_test.go b/libkpod/config_test.go
new file mode 100644
index 000000000..e6820d3c0
--- /dev/null
+++ b/libkpod/config_test.go
@@ -0,0 +1,54 @@
+package libkpod
+
+import (
+ "io/ioutil"
+ "os"
+ "testing"
+)
+
+// TestConfigToFile ensures Config.ToFile(..) encodes and writes out
+// a Config instance toa a file on disk.
+func TestConfigToFile(t *testing.T) {
+ // Test with a default configuration
+ c := DefaultConfig()
+ tmpfile, err := ioutil.TempFile("", "config")
+ if err != nil {
+ t.Fatalf("Unable to create temporary file: %+v", err)
+ }
+ // Clean up temporary file
+ defer os.Remove(tmpfile.Name())
+
+ // Make the ToFile calls
+ err = c.ToFile(tmpfile.Name())
+ // Make sure no errors occurred while populating the file
+ if err != nil {
+ t.Fatalf("Unable to write to temporary file: %+v", err)
+ }
+
+ // Make sure the file is on disk
+ if _, err := os.Stat(tmpfile.Name()); os.IsNotExist(err) {
+ t.Fatalf("The config file was not written to disk: %+v", err)
+ }
+}
+
+// TestConfigUpdateFromFile ensures Config.UpdateFromFile(..) properly
+// updates an already create Config instancec with new data.
+func TestConfigUpdateFromFile(t *testing.T) {
+ // Test with a default configuration
+ c := DefaultConfig()
+ // Make the ToFile calls
+ err := c.UpdateFromFile("testdata/config.toml")
+ // Make sure no errors occurred while populating from the file
+ if err != nil {
+ t.Fatalf("Unable update config from file: %+v", err)
+ }
+
+ // Check fields that should have changed after UpdateFromFile
+ if c.Storage != "overlay2" {
+ t.Fatalf("Update failed. Storage did not change to overlay2")
+ }
+
+ if c.RuntimeConfig.PidsLimit != 2048 {
+ t.Fatalf("Update failed. RuntimeConfig.PidsLimit did not change to 2048")
+ }
+}