From bb7659fbde8f2c6e14473801a95534f99a08dd66 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 23 May 2016 21:26:20 +0200 Subject: [PATCH] Added more tests, fixed some linter errors --- configfile.go | 24 +++++++------------ configfile_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/configfile.go b/configfile.go index 27e20e9..48d1316 100644 --- a/configfile.go +++ b/configfile.go @@ -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 } diff --git a/configfile_test.go b/configfile_test.go index c97d013..d5c6c9e 100644 --- a/configfile_test.go +++ b/configfile_test.go @@ -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"}