1
0
Fork 0
mirror of https://github.com/Luzifer/duplicity-backup.git synced 2024-11-08 07:00:09 +00:00

Added more tests, fixed some linter errors

This commit is contained in:
Knut Ahlers 2016-05-23 21:26:20 +02:00
parent 54f9391e06
commit bb7659fbde
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 67 additions and 15 deletions

View file

@ -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) {
var (
tmpArg, tmpEnv []string
tmpEnv []string
option, root, dest string
addTime bool
command = argv[0]
@ -208,25 +208,19 @@ func (c *configFile) GenerateCommand(argv []string, time string) (commandLine []
tmpEnv = c.generateCredentialExport()
env = append(env, tmpEnv...)
// Clean empty entries from the list
tmpArg = []string{}
tmpEnv = []string{}
commandLine = c.cleanSlice(commandLine)
env = c.cleanSlice(env)
for _, i := range commandLine {
return
}
func (c *configFile) cleanSlice(in []string) (out []string) {
for _, i := range in {
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
}

View file

@ -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() {
BeforeEach(func() {
argv = []string{"__remove_old"}