mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
Target for cheking not commited config files.
Signed-off-by: laurentiuNiculae <themelopeus@gmail.com> Separated updateDistSpec functionality Removed rewriting of config when distSpecVersion was wrong
This commit is contained in:
committed by
Ramkumar Chinchani
parent
efc55b013e
commit
0d4cc8736d
+18
-51
@@ -10,7 +10,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
distspec "github.com/opencontainers/distribution-spec/specs-go"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"gopkg.in/resty.v1"
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
@@ -354,6 +353,24 @@ func TestGC(t *testing.T) {
|
||||
err = cli.LoadConfiguration(config, file.Name())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("GC delay when GC = false", func() {
|
||||
config := config.New()
|
||||
|
||||
file, err := ioutil.TempFile("", "gc-false-config-*.json")
|
||||
So(err, ShouldBeNil)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
content := []byte(`{"distSpecVersion": "1.0.0", "storage": {"rootDirectory": "/tmp/zot",
|
||||
"gc": false}, "http": {"address": "127.0.0.1", "port": "8080", "ReadOnly": false},
|
||||
"log": {"level": "debug"}}`)
|
||||
|
||||
err = ioutil.WriteFile(file.Name(), content, 0o600)
|
||||
So(err, ShouldBeNil)
|
||||
err = cli.LoadConfiguration(config, file.Name())
|
||||
So(err, ShouldBeNil)
|
||||
So(config.Storage.GCDelay, ShouldEqual, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -533,53 +550,3 @@ func TestScrub(t *testing.T) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestApplyDefaultValues(t *testing.T) {
|
||||
Convey("Test rewriting of config file if version is wrong", t, func() {
|
||||
configContent := []byte(`{"distSpecVersion": "1.0.0555", "storage": {"rootDirectory": "/tmp/zot"},
|
||||
"http": {"address": "127.0.0.1", "port": "8080", "ReadOnly": false},
|
||||
"log": {"level": "debug"}}
|
||||
`)
|
||||
oldConfig := config.New()
|
||||
|
||||
file, err := ioutil.TempFile("", "default-val-test-config*.json")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
defer os.Remove(file.Name())
|
||||
_, err = file.Write(configContent)
|
||||
So(err, ShouldBeNil)
|
||||
Convey("The file can be rewritten", func() {
|
||||
err = os.Chmod(file.Name(), 0o777)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = cli.LoadConfiguration(oldConfig, file.Name())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
configContent, err = ioutil.ReadFile(file.Name())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
newConfig := config.New()
|
||||
err = json.Unmarshal(configContent, newConfig)
|
||||
So(err, ShouldBeNil)
|
||||
So(newConfig.DistSpecVersion, ShouldEqual, distspec.Version)
|
||||
So(newConfig.DistSpecVersion, ShouldEqual, distspec.Version)
|
||||
})
|
||||
|
||||
Convey("The file can't be rewritten", func() {
|
||||
err = os.Chmod(file.Name(), 0o444)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = cli.LoadConfiguration(oldConfig, file.Name())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
configContent, err = ioutil.ReadFile(file.Name())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
newConfig := config.New()
|
||||
err = json.Unmarshal(configContent, newConfig)
|
||||
So(err, ShouldBeNil)
|
||||
So(newConfig.DistSpecVersion, ShouldEqual, "1.0.0555")
|
||||
So(oldConfig.DistSpecVersion, ShouldEqual, distspec.Version)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user