diff --git a/ghbackup/run_test.go b/ghbackup/run_test.go new file mode 100644 index 0000000..7912344 --- /dev/null +++ b/ghbackup/run_test.go @@ -0,0 +1,43 @@ +package ghbackup_test + +import ( + "io/ioutil" + "os" + "testing" + + "qvl.io/ghbackup/ghbackup" +) + +func TestRun(t *testing.T) { + dir, err := ioutil.TempDir("", "qvl-backup") + if err != nil { + t.Error(err) + } + defer func() { + err := os.RemoveAll(dir) + if err != nil { + t.Error(err) + } + }() + + updates := make(chan ghbackup.Update) + go func() { + for u := range updates { + switch u.Type { + case ghbackup.UErr: + t.Error("Unexpected error:", u.Message) + } + } + }() + + err = ghbackup.Run(ghbackup.Config{ + Account: "qvl", + Dir: dir, + Secret: os.Getenv("SECRET"), + Updates: updates, + }) + + if err != nil { + t.Error("Unexpected error:", err) + } +} diff --git a/main_test.go b/main_test.go index 09a0b94..7a34b0e 100644 --- a/main_test.go +++ b/main_test.go @@ -1,9 +1,7 @@ -package main +package main_test import ( "bytes" - "io/ioutil" - "os" "os/exec" "testing" ) @@ -48,40 +46,6 @@ func TestHelp(t *testing.T) { } } -func TestRun(t *testing.T) { - dir, err := ioutil.TempDir("", "qvl-backup") - if err != nil { - t.Error(err) - } - defer func() { - err := os.RemoveAll(dir) - if err != nil { - t.Error(err) - } - }() - - // Use secret from environment if available. - // Prevents rate limiting on CI server. - secret := os.Getenv("SECRET") - var args []string - if secret == "" { - args = []string{"-account", "qvl", dir} - } else { - args = []string{"-account", "qvl", "-secret", secret, dir} - } - - stdout, stderr, ok := run(args) - if !ok { - t.Error("Non-zero exit code") - } - if stdout != "" { - t.Error("Unexpected stdout:", stdout) - } - if stderr != "" { - t.Error("Unexpected stderr:", stderr) - } -} - func run(a []string) (string, string, bool) { var outbuf, errbuf bytes.Buffer cmd := exec.Command("ghbackup", a...)