Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
separate run test
Browse files Browse the repository at this point in the history
don't depend on binary
  • Loading branch information
jorinvo committed Jan 1, 2017
1 parent 5248332 commit f7f5cde
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
43 changes: 43 additions & 0 deletions ghbackup/run_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
38 changes: 1 addition & 37 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main
package main_test

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"testing"
)
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit f7f5cde

Please sign in to comment.