mirror of
https://github.com/Luzifer/duplicity-backup.git
synced 2024-11-08 15:10:06 +00:00
Added more tests, fixed some linter errors
This commit is contained in:
parent
54f9391e06
commit
bb7659fbde
2 changed files with 67 additions and 15 deletions
|
@ -144,7 +144,7 @@ func loadConfigFile(in io.Reader) (*configFile, error) {
|
||||||
|
|
||||||
func (c *configFile) GenerateCommand(argv []string, time string) (commandLine []string, env []string, err error) {
|
func (c *configFile) GenerateCommand(argv []string, time string) (commandLine []string, env []string, err error) {
|
||||||
var (
|
var (
|
||||||
tmpArg, tmpEnv []string
|
tmpEnv []string
|
||||||
option, root, dest string
|
option, root, dest string
|
||||||
addTime bool
|
addTime bool
|
||||||
command = argv[0]
|
command = argv[0]
|
||||||
|
@ -208,25 +208,19 @@ func (c *configFile) GenerateCommand(argv []string, time string) (commandLine []
|
||||||
tmpEnv = c.generateCredentialExport()
|
tmpEnv = c.generateCredentialExport()
|
||||||
env = append(env, tmpEnv...)
|
env = append(env, tmpEnv...)
|
||||||
|
|
||||||
// Clean empty entries from the list
|
commandLine = c.cleanSlice(commandLine)
|
||||||
tmpArg = []string{}
|
env = c.cleanSlice(env)
|
||||||
tmpEnv = []string{}
|
|
||||||
|
|
||||||
for _, i := range commandLine {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *configFile) cleanSlice(in []string) (out []string) {
|
||||||
|
for _, i := range in {
|
||||||
if i != "" {
|
if i != "" {
|
||||||
tmpArg = append(tmpArg, i)
|
out = append(out, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, i := range env {
|
|
||||||
if i != "" {
|
|
||||||
tmpEnv = append(tmpEnv, i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commandLine = tmpArg
|
|
||||||
env = tmpEnv
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,64 @@ logdir: /var/log/duplicity/
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Context("Incremental backup with given config", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
argv = []string{"incr"}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should not have errored", func() {
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should have exported secrets in ENV variables", func() {
|
||||||
|
Expect(env).To(Equal([]string{
|
||||||
|
"PASSPHRASE=5pJZqnzrmFSi1wqZtcUh",
|
||||||
|
"AWS_ACCESS_KEY_ID=AKIAJKCC13246798732A",
|
||||||
|
"AWS_SECRET_ACCESS_KEY=Oosdkfjadgiuagbiajbgaliurtbjsbfgaldfbgdf",
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should have generated the expected commandLine", func() {
|
||||||
|
Expect(commandLine).To(Equal([]string{
|
||||||
|
"incr",
|
||||||
|
"--full-if-older-than", "7D",
|
||||||
|
"--s3-use-new-style",
|
||||||
|
"--include=/data",
|
||||||
|
"--exclude=**",
|
||||||
|
"/", "s3+http://my-backup/myhost/",
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("Forced full backup with given config", func() {
|
||||||
|
BeforeEach(func() {
|
||||||
|
argv = []string{"full"}
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should not have errored", func() {
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should have exported secrets in ENV variables", func() {
|
||||||
|
Expect(env).To(Equal([]string{
|
||||||
|
"PASSPHRASE=5pJZqnzrmFSi1wqZtcUh",
|
||||||
|
"AWS_ACCESS_KEY_ID=AKIAJKCC13246798732A",
|
||||||
|
"AWS_SECRET_ACCESS_KEY=Oosdkfjadgiuagbiajbgaliurtbjsbfgaldfbgdf",
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should have generated the expected commandLine", func() {
|
||||||
|
Expect(commandLine).To(Equal([]string{
|
||||||
|
"full",
|
||||||
|
"--full-if-older-than", "7D",
|
||||||
|
"--s3-use-new-style",
|
||||||
|
"--include=/data",
|
||||||
|
"--exclude=**",
|
||||||
|
"/", "s3+http://my-backup/myhost/",
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Context("auto-removal with given config", func() {
|
Context("auto-removal with given config", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
argv = []string{"__remove_old"}
|
argv = []string{"__remove_old"}
|
||||||
|
|
Loading…
Reference in a new issue