Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
More integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Jan 21, 2013
1 parent 97b1fa0 commit 6414330
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
22 changes: 4 additions & 18 deletions Makefile
Expand Up @@ -10,27 +10,13 @@ prepare:
fvb:
gofmt -e -s -w .
go tool vet .
go build -v -o gonut ./nut
go build -o gonut ./nut

test: fvb
cd ../test_nut1 && rm -f *.nut
cd ../test_nut1 && ../nut/gonut generate -v
cd ../test_nut1 && ../nut/gonut check -v
cd ../test_nut1 && ../nut/gonut pack -v
cd ../test_nut1 && ../nut/gonut check -v test_nut1-0.0.1.nut
cd ../test_nut1 && ../nut/gonut unpack -v test_nut1-0.0.1.nut
cd ../test_nut1 && ../nut/gonut pack
go test -v . ./nut -gocheck.v

go test -v ./... -gocheck.v

cd ../test_nut1 && ../nut/gonut install -p gonuts.io -v test_nut1-0.0.1.nut

cd ../test_nut2 && rm -f *.nut
cd ../test_nut2 && ../nut/gonut generate -v
cd ../test_nut2 && ../nut/gonut check -v
cd ../test_nut2 && ../nut/gonut pack -v
cd ../test_nut2 && ../nut/gonut check -v test_nut2-0.0.2.nut
cd ../test_nut2 && ../nut/gonut unpack -v test_nut2-0.0.2.nut
cd ../test_nut2 && ../nut/gonut install -v test_nut2-0.0.2.nut
go test -v ./integration_test -gocheck.v

test_server: test
cd ../test_nut1 && GONUTS_IO_SERVER=localhost:8080 ../nut/gonut publish -v test_nut1-0.0.1.nut
Expand Down
15 changes: 9 additions & 6 deletions integration_test/hook_for_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"syscall"
"testing"
Expand All @@ -15,14 +16,11 @@ import (
// Global gocheck hook.
func TestIntegration(t *testing.T) { TestingT(t) }

const (
TestNut1 = "../../test_nut1"
var (
TestNut1 = "../../test_nut1" // TODO filepath.FromSlash ?
TestNut2 = "../../test_nut2"
TestNut3 = "../../test_nut3"
)

var (
nutBin string
nutBin string
)

func init() {
Expand All @@ -32,6 +30,11 @@ func init() {
}

nutBin = filepath.Join(wd, "..", "gonut")
if runtime.GOOS == "windows" {
// required for exec
os.Rename(nutBin, nutBin+".exe")
nutBin += ".exe"
}
}

func runCommand(c *C, dir, command string, args string, exitCode ...int) (stdout, stderr string) {
Expand Down
39 changes: 36 additions & 3 deletions integration_test/local_test.go
Expand Up @@ -18,7 +18,11 @@ func (*L) SetUpTest(c *C) {
}
}

func (*L) TestGenerateCheck(c *C) {
func (l *L) TearDownTest(c *C) {
l.SetUpTest(c)
}

func (*L) TestGenerateCheckOk(c *C) {
_, stderr := runNut(c, TestNut1, "generate -v")
c.Check(stderr, Equals, "nut.json updated.")
gitNoDiff(c, TestNut1)
Expand All @@ -32,7 +36,7 @@ func (*L) TestGenerateCheck(c *C) {
expected := `
nut.json generated.
You should fix following issues:
Now you should edit nut.json to fix following errors:
Version "0.0.0" is invalid.
"Crazy Nutter" is not a real person.
Expand All @@ -43,7 +47,7 @@ After that run 'nut check' to check spec again.`[1:]

_, stderr = runNut(c, TestNut2, "check -v", 1)
expected = `
Found issues in nut.json:
Found errors in nut.json:
Version "0.0.0" is invalid.
"Crazy Nutter" is not a real person.`[1:]
c.Check(stderr, Equals, expected)
Expand All @@ -55,3 +59,32 @@ Found issues in nut.json:
_, stderr = runNut(c, TestNut3, "check -v", 1)
c.Check(strings.HasPrefix(stderr, "no Go source files in ."), Equals, true)
}

func (*L) TestPackCheckUnpackOk(c *C) {
_, stderr := runNut(c, TestNut1, "pack -v")
c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut created."), Equals, true)
gitNoDiff(c, TestNut1)

_, stderr = runNut(c, TestNut1, "check -v test_nut1-0.0.1.nut")
c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut looks good."), Equals, true)
gitNoDiff(c, TestNut1)

c.Check(os.Remove(TestNut1+"/test_nut1.go"), Equals, nil)
_, stderr = runNut(c, TestNut1, "unpack -v test_nut1-0.0.1.nut")
c.Check(strings.HasSuffix(stderr, "test_nut1-0.0.1.nut unpacked."), Equals, true)
gitNoDiff(c, TestNut1)

c.Check(os.Remove(TestNut2+"/nut.json"), Equals, nil)
runNut(c, TestNut2, "generate -v")
_, stderr = runNut(c, TestNut2, "pack -v", 1)
c.Check(strings.HasPrefix(stderr, "Found errors:"), Equals, true)
_, stderr = runNut(c, TestNut2, "pack -nc -v")
c.Check(strings.HasSuffix(stderr, "test_nut2-0.0.0.nut created."), Equals, true)

_, stderr = runNut(c, TestNut2, "check -v test_nut2-0.0.0.nut", 1)
c.Check(strings.HasPrefix(stderr, "Found errors in test_nut2-0.0.0.nut:"), Equals, true)

c.Check(os.Remove(TestNut3+"/README"), Equals, nil)
_, stderr = runNut(c, TestNut3, "pack -nc -v", 1)
c.Check(strings.HasSuffix(stderr, "README: no such file or directory"), Equals, true)
}

0 comments on commit 6414330

Please sign in to comment.