Пример #1
0
func assertUpgradeNotComplete(c *gc.C, context *upgradeWorkerContext) {
	select {
	case <-context.UpgradeComplete:
		c.Error("UpgradeComplete channel is closed but shouldn't be")
	default:
	}
}
Пример #2
0
func assertUpgradeComplete(c *gc.C, context *upgradeWorkerContext) {
	select {
	case <-context.UpgradeComplete:
	default:
		c.Error("UpgradeComplete channel is open but shouldn't be")
	}
}
Пример #3
0
func (s *BootstrapSuite) TestBootstrapKeepBroken(c *gc.C) {
	resetJujuHome(c)
	devVersion := version.Current
	// Force a dev version by having a non zero build number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	devVersion.Build = 1234
	s.PatchValue(&version.Current, devVersion)
	opc, errc := cmdtesting.RunCommand(cmdtesting.NullContext(c), envcmd.Wrap(new(BootstrapCommand)), "-e", "brokenenv", "--keep-broken")
	err := <-errc
	c.Assert(err, gc.ErrorMatches, "failed to bootstrap environment: dummy.Bootstrap is broken")
	done := false
	for !done {
		select {
		case op, ok := <-opc:
			if !ok {
				done = true
				break
			}
			switch op.(type) {
			case dummy.OpDestroy:
				c.Error("unexpected call to env.Destroy")
				break
			}
		default:
			break
		}
	}
}
Пример #4
0
func (s *S) TestFakeQPubSubUnSub(c *gocheck.C) {
	q := FakePubSubQ{}
	msgChan, err := q.Sub()
	c.Assert(err, gocheck.IsNil)
	err = q.Pub([]byte("arrakis"))
	c.Assert(err, gocheck.IsNil)
	done := make(chan bool)
	go func() {
		time.Sleep(5e8)
		q.UnSub()
	}()
	go func() {
		msgs := make([][]byte, 0)
		for msg := range msgChan {
			msgs = append(msgs, msg)
		}
		c.Assert(msgs, gocheck.DeepEquals, [][]byte{[]byte("arrakis")})
		done <- true
	}()
	select {
	case <-done:
	case <-time.After(1e9):
		c.Error("Timeout waiting for message.")
	}
}
Пример #5
0
func (s *RedismqSuite) TestRedisPubSubUnsub(c *gocheck.C) {
	var factory redismqQFactory
	q, err := factory.Get("mypubsub")
	c.Assert(err, gocheck.IsNil)
	pubSubQ, ok := q.(PubSubQ)
	c.Assert(ok, gocheck.Equals, true)
	msgChan, err := pubSubQ.Sub()
	c.Assert(err, gocheck.IsNil)
	err = pubSubQ.Pub([]byte("anla'shok"))
	c.Assert(err, gocheck.IsNil)
	done := make(chan bool)
	go func() {
		time.Sleep(5e8)
		pubSubQ.UnSub()
	}()
	go func() {
		msgs := make([][]byte, 0)
		for msg := range msgChan {
			msgs = append(msgs, msg)
		}
		c.Assert(msgs, gocheck.DeepEquals, [][]byte{[]byte("anla'shok")})
		done <- true
	}()
	select {
	case <-done:
	case <-time.After(1e9):
		c.Error("Timeout waiting for message.")
	}
}
Пример #6
0
func (s *BootstrapSuite) TestBootstrapDestroy(c *gc.C) {
	resetJujuHome(c)
	devVersion := version.Current
	// Force a dev version by having a non zero build number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	devVersion.Build = 1234
	s.PatchValue(&version.Current, devVersion)
	opc, errc := cmdtesting.RunCommand(cmdtesting.NullContext(c), envcmd.Wrap(new(BootstrapCommand)), "-e", "brokenenv")
	err := <-errc
	c.Assert(err, gc.ErrorMatches, "failed to bootstrap environment: dummy.Bootstrap is broken")
	var opDestroy *dummy.OpDestroy
	for opDestroy == nil {
		select {
		case op := <-opc:
			switch op := op.(type) {
			case dummy.OpDestroy:
				opDestroy = &op
			}
		default:
			c.Error("expected call to env.Destroy")
			return
		}
	}
	c.Assert(opDestroy.Error, gc.ErrorMatches, "dummy.Destroy is broken")
}
Пример #7
0
func (s *WaitTickerTestSuite) TestWaitTicker(t *gocheck.C) {
	wt := ticker.NewWaitTicker(2)

	tickChan := make(chan time.Time)
	wt.Add(tickChan)
	go wt.Run(0)

	ticks := []time.Time{time.Now()}
	for i := 0; i < 2; i++ {
		now := <-tickChan
		ticks = append(ticks, now)
	}
	wt.Stop()

	t.Assert(len(ticks), gocheck.Equals, 3)

	d := ticks[1].Sub(ticks[0])
	if d.Seconds() >= 1.0 {
		t.Error("Ticks when receiver ready; got %f", d.Seconds())
	}

	d = ticks[2].Sub(ticks[1])
	if d.Seconds() < 1.9 || d.Seconds() > 2.5 {
		t.Error("Waits interval seconds; got %f", d.Seconds())
	}
}
Пример #8
0
func (s *IntegrationTestSuite) assertContainerRestarts(c *chk.C, id containers.Identifier) {
	isStarted := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "deactivating" || active == "activating" {
			return false
		}
		c.Errorf("Unit %s restart failed (%s) in unexpected state %s", id, active, sub)
		c.FailNow()
		return false
	}

	if !until(CONTAINER_STATE_CHANGE_TIMEOUT, CONTAINER_CHECK_INTERVAL, isStarted) {
		active, sub := s.unitState(id)
		c.Errorf("Timeout during restart of %s, never got back to 'active' state (%s/%s)", id, active, sub)
		c.FailNow()
	}

	container, err := s.dockerClient.GetContainer(id.ContainerFor(), false)
	if err != nil {
		c.Error("Can't check container "+id, err)
		c.FailNow()
	}
	if !container.State.Running {
		c.Logf("Container %s exists, but is not running - race condition %+v", id, container.State)
	}
}
Пример #9
0
func (t *testWrap) TestMpris(c *C.C) {
	os.Setenv("XDG_DATA_DIRS", "testdata/share")
	if _, ok := getCommandByMimeType("text/plain"); ok == false {
		c.Error("getCommandByMimeType failed")
		return
	}
}
Пример #10
0
func (s *BootstrapSuite) TestBootstrapDestroy(c *gc.C) {
	_, fake := makeEmptyFakeHome(c)
	defer fake.Restore()
	devVersion := version.Current
	// Force a dev version by having an odd minor version number.
	// This is because we have not uploaded any tools and auto
	// upload is only enabled for dev versions.
	devVersion.Minor = 11
	s.PatchValue(&version.Current, devVersion)
	opc, errc := runCommand(nullContext(c), new(BootstrapCommand), "-e", "brokenenv")
	err := <-errc
	c.Assert(err, gc.ErrorMatches, "dummy.Bootstrap is broken")
	var opDestroy *dummy.OpDestroy
	for opDestroy == nil {
		select {
		case op := <-opc:
			switch op := op.(type) {
			case dummy.OpDestroy:
				opDestroy = &op
			}
		default:
			c.Error("expected call to env.Destroy")
			return
		}
	}
	c.Assert(opDestroy.Error, gc.ErrorMatches, "dummy.Destroy is broken")
}
Пример #11
0
func (s *FoundationS) TestSkip(c *gocheck.C) {
	helper := SkipTestHelper{}
	output := String{}
	gocheck.Run(&helper, &gocheck.RunConf{Output: &output})

	if output.value != "" {
		c.Error("Skip() logged something:\n", output.value)
	}
}
Пример #12
0
func (s *FoundationS) TestError(c *gocheck.C) {
	expectedLog := fmt.Sprintf("foundation_test.go:%d:\n"+
		"    c\\.Error\\(\"Error \", \"message!\"\\)\n"+
		"\\.\\.\\. Error: Error message!\n\n",
		getMyLine()+1)
	c.Error("Error ", "message!")
	checkState(c, nil,
		&expectedState{
			name:   "Error(`Error `, `message!`)",
			failed: true,
			log:    expectedLog,
		})
}
Пример #13
0
func (s *IntegrationTestSuite) assertContainerStarts(c *chk.C, id containers.Identifier) {
	active, _ := s.unitState(id)
	switch active {
	case "active":
		return
	case "activating":
		break
	default:
		c.Errorf("Container %s failed to start - %s", id, active)
		c.FailNow()
		return
	}

	isRunning := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "activating" {
			return false
		}
		c.Errorf("Unit %s start failed with state %s", id, sub)
		c.FailNow()
		return false
	}

	if !until(TimeoutContainerStateChange, time.Second/20, isRunning) {
		c.Errorf("Timeout during start of %s, never got to 'active' state", id)
		c.FailNow()
	}

	// Docker does not immediately return container status - possibly due to races inside of the
	// daemon
	failed := false
	isContainerUp := func() bool {
		done, err := isContainerAvailable(s.dockerClient, id.ContainerFor())
		if err != nil {
			failed = true
			c.Error("Docker couldn't return container info", err)
			c.FailNow()
		}
		return done
	}

	if !until(TimeoutDockerWait, IntervalHttpCheck, isContainerUp) {
		if !failed {
			c.Errorf("Docker never reported the container running %s", id)
		}
		c.FailNow()
	}
}
Пример #14
0
func (s *FoundationS) TestSucceedNow(c *gocheck.C) {
	defer (func() {
		if c.Failed() {
			c.Error("SucceedNow() didn't succeed the test")
		}
		if c.GetTestLog() != "" {
			c.Error("Something got logged:\n" + c.GetTestLog())
		}
	})()

	c.Fail()
	c.SucceedNow()
	c.Log("SucceedNow() didn't stop the test")
}
Пример #15
0
func (s *BootstrapS) TestMinLogger(c *gocheck.C) {
	var logger minLogger
	logger = log.New(os.Stderr, "", 0)
	logger = c
	logger.Output(0, "Hello there")
	expected := "\\[LOG\\] [.0-9]+ Hello there\n"
	output := c.GetTestLog()
	matched, err := regexp.MatchString(expected, output)
	if err != nil {
		c.Error("Bad expression: ", expected)
	} else if !matched {
		c.Error("Output() didn't log properly:\n", output)
	}
}
Пример #16
0
func (s *FoundationS) TestSkipVerbose(c *gocheck.C) {
	helper := SkipTestHelper{}
	output := String{}
	gocheck.Run(&helper, &gocheck.RunConf{Output: &output, Verbose: true})

	expected := "SKIP: foundation_test\\.go:[0-9]+: SkipTestHelper\\.TestFail" +
		" \\(Wrong platform or whatever\\)"
	matched, err := regexp.MatchString(expected, output.value)
	if err != nil {
		c.Error("Bad expression: ", expected)
	} else if !matched {
		c.Error("Skip() didn't log properly:\n", output.value)
	}
}
Пример #17
0
func (s *DynamoDBTest) TearDownSuite(c *gocheck.C) {
	// return immediately in the case of calling c.Skip() in SetUpSuite()
	if s.server == nil {
		return
	}

	// check whether the table exists
	if tables, err := s.server.ListTables(); err != nil {
		c.Fatal(err)
	} else {
		if !findTableByName(tables, s.TableDescriptionT.TableName) {
			return
		}
	}

	// Delete the table and wait
	if _, err := s.server.DeleteTable(s.TableDescriptionT); err != nil {
		c.Fatal(err)
	}

	done := make(chan bool)
	timeout := time.After(TIMEOUT)
	go func() {
		for {
			select {
			case <-done:
				return
			default:
				tables, err := s.server.ListTables()
				if err != nil {
					c.Fatal(err)
				}
				if findTableByName(tables, s.TableDescriptionT.TableName) {
					time.Sleep(5 * time.Second)
				} else {
					done <- true
					return
				}
			}
		}
	}()
	select {
	case <-done:
		break
	case <-timeout:
		c.Error("Expect the table to be deleted but timed out")
		close(done)
	}
}
Пример #18
0
func (s *S) TestStresstest(c *gocheck.C) {
	if skipStress {
		c.Skip("Skipped stresstest")
	}
	LogLevel = 1
	p := NewParser(strings.NewReader(backgroundSuite), "background")
	var background *Suite
	var err os.Error
	background, err = p.ReadSuite()
	if err != nil {
		c.Fatalf("Cannot read suite: %s", err.String())
	}
	p = NewParser(strings.NewReader(stressSuite), "suite")
	var suite *Suite
	suite, err = p.ReadSuite()
	if err != nil {
		c.Fatalf("Cannot read suite: %s", err.String())
	}

	r0 := suite.Stresstest(background, 0, 3, 100)
	r10 := suite.Stresstest(background, 10, 3, 100)
	r30 := suite.Stresstest(background, 30, 2, 100)
	time.Sleep(100000000)
	r60 := suite.Stresstest(background, 60, 1, 100)
	time.Sleep(100000000)
	r100 := suite.Stresstest(background, 100, 1, 100)
	time.Sleep(200000000)
	r150 := suite.Stresstest(background, 150, 1, 100)
	time.Sleep(200000000)
	r200 := suite.Stresstest(background, 200, 5, 100)
	time.Sleep(200000000)

	testPrintStResult("Load    0", r0)
	testPrintStResult("Load   10", r10)
	testPrintStResult("Load   30", r30)
	testPrintStResult("Load   60", r60)
	testPrintStResult("Load  100", r100)
	testPrintStResult("Load  150", r150)
	testPrintStResult("Load  200", r200)
	if r0.Total <= 0 || r0.N <= 0 {
		c.Error("No tests run without load")
		c.FailNow()
	}
	if r0.Fail > 0 || r0.Err > 0 {
		c.Error("Failures without load")
		c.FailNow()
	}

}
Пример #19
0
func (s *S) TestProvisionerDestroy(c *gocheck.C) {
	fexec := &etesting.FakeExecutor{}
	execut = fexec
	defer func() {
		execut = nil
	}()
	w := new(bytes.Buffer)
	l := stdlog.New(w, "", stdlog.LstdFlags)
	log.SetLogger(l)
	app := testing.NewFakeApp("myapp", "python", 1)
	u := provision.Unit{
		Name:       app.ProvisionUnits()[0].GetName(),
		AppName:    app.GetName(),
		Machine:    app.ProvisionUnits()[0].GetMachine(),
		InstanceId: app.ProvisionUnits()[0].GetInstanceId(),
		Status:     provision.StatusCreating,
	}
	err := s.conn.Collection(s.collName).Insert(&u)
	c.Assert(err, gocheck.IsNil)
	img := image{Name: app.GetName()}
	err = s.conn.Collection(s.imageCollName).Insert(&img)
	c.Assert(err, gocheck.IsNil)
	var p DockerProvisioner
	c.Assert(p.Destroy(app), gocheck.IsNil)
	ok := make(chan bool, 1)
	go func() {
		for {
			coll := s.conn.Collection(s.collName)
			ct, err := coll.Find(bson.M{"name": u.Name}).Count()
			if err != nil {
				c.Fatal(err)
			}
			if ct == 0 {
				ok <- true
				return
			}
			runtime.Gosched()
		}
	}()
	select {
	case <-ok:
	case <-time.After(10e9):
		c.Error("Timed out waiting for the container to be destroyed (10 seconds)")
	}
	args := []string{"stop", "i-01"}
	c.Assert(fexec.ExecutedCmd("docker", args), gocheck.Equals, true)
	args = []string{"rm", "i-01"}
	c.Assert(fexec.ExecutedCmd("docker", args), gocheck.Equals, true)
}
Пример #20
0
func (s *ItemSuite) TestPutGetDeleteItem(c *gocheck.C) {
	attrs := []dynamodb.Attribute{
		*dynamodb.NewStringAttribute("Attr1", "Attr1Val"),
	}

	var rk string
	if s.WithRange {
		rk = "1"
	}

	// Put
	if ok, err := s.table.PutItem("NewHashKeyVal", rk, attrs); !ok {
		c.Fatal(err)
	}

	// Get to verify Put operation
	pk := &dynamodb.Key{HashKey: "NewHashKeyVal", RangeKey: rk}
	item, err := s.table.GetItem(pk)
	if err != nil {
		c.Fatal(err)
	}

	if val, ok := item["TestHashKey"]; ok {
		c.Check(val, gocheck.DeepEquals, dynamodb.NewStringAttribute("TestHashKey", "NewHashKeyVal"))
	} else {
		c.Error("Expect TestHashKey to be found")
	}

	if s.WithRange {
		if val, ok := item["TestRangeKey"]; ok {
			c.Check(val, gocheck.DeepEquals, dynamodb.NewNumericAttribute("TestRangeKey", "1"))
		} else {
			c.Error("Expect TestRangeKey to be found")
		}
	}

	// Delete
	if ok, _ := s.table.DeleteItem(pk); !ok {
		c.Fatal(err)
	}

	// Get to verify Delete operation
	_, err = s.table.GetItem(pk)
	c.Check(err.Error(), gocheck.Matches, "Item not found")
}
Пример #21
0
func (s *FoundationS) TestExpectFailureSucceedVerbose(c *gocheck.C) {
	helper := ExpectFailureSucceedHelper{}
	output := String{}
	result := gocheck.Run(&helper, &gocheck.RunConf{Output: &output, Verbose: true})

	expected := "" +
		"FAIL EXPECTED: foundation_test\\.go:[0-9]+:" +
		" ExpectFailureSucceedHelper\\.TestSucceed \\(It booms!\\)\t *[.0-9]+s\n"

	matched, err := regexp.MatchString(expected, output.value)
	if err != nil {
		c.Error("Bad expression: ", expected)
	} else if !matched {
		c.Error("ExpectFailure() didn't log properly:\n", output.value)
	}

	c.Assert(result.ExpectedFailures, gocheck.Equals, 1)
}
Пример #22
0
func (s *TableSuite) TestCreateListTable(c *gocheck.C) {
	status, err := s.server.CreateTable(s.TableDescriptionT)
	if err != nil {
		c.Fatal(err)
	}
	if status != "ACTIVE" && status != "CREATING" {
		c.Error("Expect status to be ACTIVE or CREATING")
	}

	s.WaitUntilStatus(c, "ACTIVE")

	tables, err := s.server.ListTables()
	if err != nil {
		c.Fatal(err)
	}
	c.Check(len(tables), gocheck.Not(gocheck.Equals), 0)
	c.Check(findTableByName(tables, s.TableDescriptionT.TableName), gocheck.Equals, true)
}
Пример #23
0
func (s *CleanupHomeTestSuite) Test_HomeCleanup_Clean_1(c *gocheck.C) {
	homePath := filepath.Join(basePath, "home", "te", "test-service")
	os.MkdirAll(homePath, (os.FileMode)(0775))

	unitFile := filepath.Join(basePath, "units", "te", "ctr-test-service.service")
	c.Assert(fileExist(unitFile), gocheck.Equals, false, gocheck.Commentf("unitFile: %s", unitFile))

	context, info, error := newContext(false, true)
	plugin := &HomeCleanup{homePath: filepath.Join(basePath, "home")}
	plugin.Clean(context)

	c.Assert(fileExist(homePath), gocheck.Equals, false, gocheck.Commentf("homePath: %s", homePath))

	if 0 != error.Len() {
		c.Log(info)
		c.Error(error)
	}
}
Пример #24
0
func (s *S) TestUnbindMultiUnits(c *gocheck.C) {
	var calls int32
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		i := atomic.LoadInt32(&calls)
		i++
		atomic.StoreInt32(&calls, i)
		w.WriteHeader(http.StatusNoContent)
	}))
	defer ts.Close()
	srvc := service.Service{Name: "mysql", Endpoint: map[string]string{"production": ts.URL}}
	err := srvc.Create()
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Services().Remove(bson.M{"_id": "mysql"})
	instance := service.ServiceInstance{
		Name:        "my-mysql",
		ServiceName: "mysql",
		Teams:       []string{s.team.Name},
		Apps:        []string{"painkiller"},
	}
	instance.Create()
	defer s.conn.ServiceInstances().Remove(bson.M{"name": "my-mysql"})
	a, err := createTestApp(s.conn, "painkiller", "", []string{s.team.Name})
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Apps().Remove(bson.M{"name": a.Name})
	app.Provisioner.Provision(&a)
	defer app.Provisioner.Destroy(&a)
	app.Provisioner.AddUnits(&a, 1)
	err = instance.UnbindApp(&a)
	c.Assert(err, gocheck.IsNil)
	ok := make(chan bool, 1)
	go func() {
		t := time.Tick(1)
		for _ = <-t; atomic.LoadInt32(&calls) < 2; _ = <-t {
		}
		ok <- true
	}()
	select {
	case <-ok:
		c.SucceedNow()
	case <-time.After(1 * time.Second):
		c.Error("endpoint not called")
	}
}
Пример #25
0
func (*GrubTester) TestGetplJsonData(c *C.C) {
	testJSONContent := `{
    "BrightScheme":{"ItemColor":"#a6a6a6","SelectedItemColor":"#05abcf", "TerminalBox":"terminal_box_bright_*.png", "MenuPixmapStyle":"menu_box_bright_*.png", "ScrollbarThumb":"scrollbar_bright_*.png"},
    "DarkScheme":{"ItemColor":"#a6a6a6","SelectedItemColor":"#05abcf", "TerminalBox":"terminal_box_dark_*.png", "MenuPixmapStyle":"menu_box_dark_*.png", "ScrollbarThumb":"scrollbar_dark_*.png"},
    "CurrentScheme":{"ItemColor":"#a6a6a6","SelectedItemColor":"#05abcf", "TerminalBox":"terminal_box_dark_*.png", "MenuPixmapStyle":"menu_box_dark_*.png", "ScrollbarThumb":"scrollbar_dark_*.png"}
}`
	wantJSONData := &TplJSONData{
		ThemeScheme{"#a6a6a6", "#05abcf", "terminal_box_bright_*.png", "menu_box_bright_*.png", "scrollbar_bright_*.png"},
		ThemeScheme{"#a6a6a6", "#05abcf", "terminal_box_dark_*.png", "menu_box_dark_*.png", "scrollbar_dark_*.png"},
		ThemeScheme{"#a6a6a6", "#05abcf", "terminal_box_dark_*.png", "menu_box_dark_*.png", "scrollbar_dark_*.png"},
	}

	theme := &Theme{}
	jsonData, err := theme.getTplJSONData([]byte(testJSONContent))
	if err != nil {
		c.Error(err)
	}
	c.Check(*jsonData, C.Equals, *wantJSONData)
}
Пример #26
0
func (s *IntegrationTestSuite) assertContainerStarts(c *chk.C, id containers.Identifier) {
	active, _ := s.unitState(id)
	switch active {
	case "active":
		return
	case "activating":
		break
	default:
		c.Errorf("Container %s failed to start - %s", id, active)
		c.FailNow()
		return
	}

	isRunning := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "activating" {
			return false
		}
		c.Errorf("Unit %s start failed with state %s", id, sub)
		c.FailNow()
		return false
	}

	if !until(CONTAINER_STATE_CHANGE_TIMEOUT, time.Second/20, isRunning) {
		c.Errorf("Timeout during start of %s, never got to 'active' state", id)
		c.FailNow()
	}

	container, err := s.dockerClient.GetContainer(id.ContainerFor(), false)
	if err != nil {
		c.Error("Can't check container "+id, err)
		c.FailNow()
	}
	if !container.State.Running {
		c.Logf("Container %s exists, but is not running - race condition %+v", id, container.State)
		//c.Errorf("Container %s is not running %+v", id, container)
		//c.FailNow()
	}
}
Пример #27
0
func (s *InterpreterSuite) TestInterpreterArbitraryArguments(c *gc.C) {
	input := `((lambda (x y . z) z) 3 4 5 6)` // => (5 6)  # see R7RS 4.1.4
	result, err := Interpret(input)
	c.Check(err, gc.IsNil, gc.Commentf("Interpret() failed: %v", err))
	if pair, is_pair := result.(Pair); is_pair {
		if pair.Len() != 2 {
			c.Error("expected lambda to return a list of two")
		} else {
			checkInteger(pair.First(), 5, c)
			checkInteger(pair.Second(), 6, c)
		}
	} else {
		c.Errorf("expected lambda to return a list, got %T", result)
	}
	// single argument symbol receives all values (R7RS 4.1.4)
	input = `((lambda x x) 3 4 5 6)`
	result, err = Interpret(input)
	c.Check(err, gc.IsNil, gc.Commentf("Interpret() failed: %v", err))
	c.Check(stringify(result), gc.Equals, "(3 4 5 6)")
}
Пример #28
0
func (s *FoundationS) TestExpectFailureFail(c *gocheck.C) {
	helper := ExpectFailureFailHelper{}
	output := String{}
	result := gocheck.Run(&helper, &gocheck.RunConf{Output: &output})

	expected := "" +
		"^\n-+\n" +
		"FAIL: foundation_test\\.go:[0-9]+:" +
		" ExpectFailureFailHelper\\.TestFail\n\n" +
		"\\.\\.\\. Error: Test succeeded, but was expected to fail\n" +
		"\\.\\.\\. Reason: Bug #XYZ\n$"

	matched, err := regexp.MatchString(expected, output.value)
	if err != nil {
		c.Error("Bad expression: ", expected)
	} else if !matched {
		c.Error("ExpectFailure() didn't log properly:\n", output.value)
	}

	c.Assert(result.ExpectedFailures, gocheck.Equals, 0)
}
Пример #29
0
func (s *FoundationS) TestFatalf(c *gocheck.C) {
	var line int
	defer (func() {
		if !c.Failed() {
			c.Error("Fatalf() didn't fail the test")
		} else {
			c.Succeed()
			expected := fmt.Sprintf("foundation_test.go:%d:\n"+
				"    c.Fatalf(\"Die %%s!\", \"now\")\n"+
				"... Error: Die now!\n\n",
				line)
			if c.GetTestLog() != expected {
				c.Error("Incorrect log:", c.GetTestLog())
			}
		}
	})()

	line = getMyLine() + 1
	c.Fatalf("Die %s!", "now")
	c.Log("Fatalf() didn't stop the test")
}
Пример #30
0
func (s *IntegrationTestSuite) assertContainerRestarts(c *chk.C, id containers.Identifier) {
	isStarted := func() bool {
		active, sub := s.unitState(id)
		if active == "active" {
			return true
		}
		if active == "deactivating" || active == "activating" {
			return false
		}
		c.Errorf("Unit %s restart failed (%s) in unexpected state %s", id, active, sub)
		c.FailNow()
		return false
	}

	if !until(TimeoutContainerStateChange, IntervalContainerCheck, isStarted) {
		active, sub := s.unitState(id)
		c.Errorf("Timeout during restart of %s, never got back to 'active' state (%s/%s)", id, active, sub)
		c.FailNow()
	}

	// Docker does not immediately return container status - possibly due to races inside of the
	// daemon
	failed := false
	isContainerUp := func() bool {
		done, err := isContainerAvailable(s.dockerClient, id.ContainerFor())
		if err != nil {
			failed = true
			c.Error("Docker couldn't return container info", err)
			c.FailNow()
		}
		return done
	}

	if !until(TimeoutDockerWait, IntervalHttpCheck, isContainerUp) {
		if !failed {
			c.Errorf("Docker never reported the container running %s", id)
		}
		c.FailNow()
	}
}