Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
enable gear build integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed May 23, 2014
1 parent 178db29 commit 83ce659
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
7 changes: 7 additions & 0 deletions contrib/test
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ go test $(find . -name *_test.go -printf "%h\n" | grep -v /vendor/ | grep -v /te

if $test_integration; then
echo -e "\nRunning integration tests\n"

# build the sti images needed for the gear build integration tests
echo -e "Building sti test images...."
pushd sti/test_images
./buildimages.sh
echo -e "done"
popd
go test -tags integration -c github.com/openshift/geard/tests $test_opts
sudo ./tests.test -gocheck.v $test_opts
fi
60 changes: 25 additions & 35 deletions tests/build_tests.go → tests/build_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// +build integration

package tests

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"github.com/fsouza/go-dockerclient"
"io/ioutil"
. "launchpad.net/gocheck"
"net/http"
"os"
"os/exec"
"time"

cjobs "github.com/openshift/geard/containers/jobs"
chk "launchpad.net/gocheck"
)

var buildTests = flag.Bool("build", false, "Include build integration tests")
var _ = chk.Suite(&BuildIntegrationTestSuite{})

// if set to false, then to run these tests, run "contrib/tests -a -o -build"
var buildTests = flag.Bool("build", true, "Include build integration tests")

/*
* The REST API needs a unique request id per HTTP request.
Expand All @@ -45,7 +44,7 @@ type BuildIntegrationTestSuite struct {
}

// Register BuildIntegrationTestSuite with the gocheck suite manager
var _ = Suite(&BuildIntegrationTestSuite{})
//var _ = Suite(&BuildIntegrationTestSuite{})

func (s *BuildIntegrationTestSuite) requestId() int {
return s.requestIdGen.requestId()
Expand All @@ -71,44 +70,45 @@ func (s *BuildIntegrationTestSuite) SetUpTest(c *C) {
}

// TestXxxx methods are identified as test cases
func (s *BuildIntegrationTestSuite) TestCleanBuild(c *C) {
func (s *BuildIntegrationTestSuite) TestBuild(c *C) {
extendedParams := cjobs.BuildImageRequest{
Tag: "geard/fake-app",
Source: "git://github.com/pmorie/simple-html",
BaseImage: "pmorie/sti-fake",
BaseImage: "sti_test/sti-fake",
Clean: true,
Verbose: true,
}

// initial/clean build.
s.buildImage(c, extendedParams)
s.checkForImage(c, extendedParams.Tag)

containerId := s.createContainer(c, extendedParams.Tag)
defer s.removeContainer(containerId)
s.checkBasicBuildState(c, containerId)
}

func (s *BuildIntegrationTestSuite) buildImage(c *C, extendedParams cjobs.BuildImageRequest) {
url := fmt.Sprintf("http://localhost:%s/build-image", s.daemonPort)
b, _ := json.Marshal(extendedParams)
req, _ := http.NewRequest("POST", url, bytes.NewReader(b))
req.Header.Set("Content-Type", "application/json")
req.ParseForm()
// incremental build
extendedParams.Clean = false
s.buildImage(c, extendedParams)

client := &http.Client{}
resp, err := client.Do(req)
c.Assert(err, IsNil, Commentf("Failed to start build"))
defer resp.Body.Close()
incrementalContainerId := s.createContainer(c, extendedParams.Tag)
defer s.removeContainer(incrementalContainerId)
s.checkBasicBuildState(c, incrementalContainerId)
s.checkIncrementalBuildState(c, incrementalContainerId)

body, err := ioutil.ReadAll(resp.Body)
}

c.Logf("Response Body: %s", body)
c.Assert(resp.StatusCode, Equals, 202, Commentf("Bad response: %+v Body: %s", resp, body))
func (s *BuildIntegrationTestSuite) buildImage(c *C, extendedParams cjobs.BuildImageRequest) {

cmd := exec.Command("/usr/bin/gear", "build", extendedParams.Source, extendedParams.BaseImage, extendedParams.Tag)
data, err := cmd.CombinedOutput()
c.Log(string(data))
c.Assert(err, chk.IsNil)
}

func (s *BuildIntegrationTestSuite) checkForImage(c *C, tag string) {
_, err := s.dockerClient.InspectImage(tag)
c.Assert(err, IsNil, Commentf("Couldn't find built image"))
c.Assert(err, IsNil, Commentf("Couldn't find built image %s", tag))
}

func (s *BuildIntegrationTestSuite) createContainer(c *C, image string) string {
Expand Down Expand Up @@ -136,7 +136,7 @@ func (s *BuildIntegrationTestSuite) checkFileExists(c *C, cId string, filePath s
}

func (s *BuildIntegrationTestSuite) checkBasicBuildState(c *C, cId string) {
s.checkFileExists(c, cId, "/sti-fake/prepare-invoked")
s.checkFileExists(c, cId, "/sti-fake/assemble-invoked")
s.checkFileExists(c, cId, "/sti-fake/run-invoked")
s.checkFileExists(c, cId, "/sti-fake/src/index.html")
}
Expand All @@ -145,13 +145,3 @@ func (s *BuildIntegrationTestSuite) checkIncrementalBuildState(c *C, cId string)
s.checkBasicBuildState(c, cId)
s.checkFileExists(c, cId, "/sti-fake/save-artifacts-invoked")
}

func (s *BuildIntegrationTestSuite) checkExtendedBuildState(c *C, cId string) {
s.checkFileExists(c, cId, "/sti-fake/prepare-invoked")
s.checkFileExists(c, cId, "/sti-fake/run-invoked")
}

func (s *BuildIntegrationTestSuite) checkIncrementalExtendedBuildState(c *C, cId string) {
s.checkExtendedBuildState(c, cId)
s.checkFileExists(c, cId, "/sti-fake/src/save-artifacts-invoked")
}

0 comments on commit 83ce659

Please sign in to comment.