Beispiel #1
0
func (s *BootstrapS) TestFailedAndSucceed(c *gocheck.C) {
	c.Fail()
	c.Succeed()
	if c.Failed() {
		critical("c.Succeed() didn't put the test back in a non-failed state")
	}
}
func (s *S) TestRetire(c *gocheck.C) {
	defer func() {
		if r := recover(); !c.Failed() && r == nil {
			c.Errorf("Should panic in ping, but did not!")
		}
	}()
	Open("127.0.0.1:27017", "tsuru_storage_test")
	sess := conn["127.0.0.1:27017"]
	sess.used = sess.used.Add(-1 * 2 * period)
	conn["127.0.0.1:27017"] = sess
	var ticker time.Ticker
	ch := make(chan time.Time, 1)
	ticker.C = ch
	ch <- time.Now()
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		retire(&ticker)
		wg.Done()
	}()
	close(ch)
	wg.Wait()
	_, ok := conn["127.0.0.1:27017"]
	c.Check(ok, gocheck.Equals, false)
	sess.s.Ping()
}
Beispiel #3
0
func (s *S) TestReadGFF(c *check.C) {
	obtain := []*feat.Feature{}
	if r, err := NewReaderName(G[0]); err != nil {
		c.Fatalf("Failed to open %q: %s", G[0], err)
	} else {
		for i := 0; i < 3; i++ {
			for {
				if f, err := r.Read(); err != nil {
					if err == io.EOF {
						break
					} else {
						c.Fatalf("Failed to read %q: %s", G[0], err)
					}
				} else {
					obtain = append(obtain, f)
				}
			}
			if c.Failed() {
				break
			}
			if len(obtain) == len(expect) {
				for j := range obtain {
					c.Check(*obtain[j], check.DeepEquals, expect[j])
				}
			} else {
				c.Check(len(obtain), check.Equals, len(expect))
			}
		}
		c.Check(r.Type, check.Equals, bio.Moltype(0))
		r.Close()
	}
}
Beispiel #4
0
func (s *S) TestColor(c *check.C) {
	for r := 0; r < 256; r += 5 {
		for g := 0; g < 256; g += 5 {
			for b := 0; b < 256; b += 5 {
				col := color.RGBA{uint8(r), uint8(g), uint8(b), 0}
				cDirectR, cDirectG, cDirectB, cDirectA := col.RGBA()
				hsva := RGBAtoHSVA(col.RGBA())
				c.Check(hsva.H, floatWithinRange, float64(0), float64(360))
				c.Check(hsva.S, floatWithinRange, float64(0), float64(1))
				c.Check(hsva.V, floatWithinRange, float64(0), float64(1))
				cFromHSVR, cFromHSVG, cFromHSVB, cFromHSVA := hsva.RGBA()
				c.Check(cFromHSVR, uintWithinRange, uint32(0), uint32(0xFFFF))
				c.Check(cFromHSVG, uintWithinRange, uint32(0), uint32(0xFFFF))
				c.Check(cFromHSVB, uintWithinRange, uint32(0), uint32(0xFFFF))
				back := RGBAtoHSVA(color.RGBA{uint8(cFromHSVR >> 8), uint8(cFromHSVG >> 8), uint8(cFromHSVB >> 8), uint8(cFromHSVA)}.RGBA())
				c.Check(hsva, check.Equals, back)
				c.Check(cFromHSVR, withinEpsilon, cDirectR, e)
				c.Check(cFromHSVG, withinEpsilon, cDirectG, e)
				c.Check(cFromHSVB, withinEpsilon, cDirectB, e)
				c.Check(cFromHSVA, check.Equals, cDirectA)
				if c.Failed() {
					return
				}
			}
		}
	}
}
Beispiel #5
0
func (s *BootstrapS) TestFailedAndFail(c *gocheck.C) {
	if c.Failed() {
		critical("c.Failed() must be false first!")
	}
	c.Fail()
	if !c.Failed() {
		critical("c.Fail() didn't put the test in a failed state!")
	}
	c.Succeed()
}
Beispiel #6
0
func (s *S) TestCollectionClose(c *gocheck.C) {
	defer func() {
		if r := recover(); !c.Failed() && r == nil {
			c.Errorf("Should panic in ping, but did not!")
		}
	}()
	storage, _ := Open("127.0.0.1:27017", "tsuru_storage_test")
	coll := Collection{storage.Collection("something").Collection}
	coll.Close()
	storage.session.Ping()
}
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")
}
func (s *FoundationS) TestErrorf(c *gocheck.C) {
	// Do not use checkState() here.  It depends on Errorf() working.
	expectedLog := fmt.Sprintf("foundation_test.go:%d:\n"+
		"    c.Errorf(\"Error %%v!\", \"message\")\n"+
		"... Error: Error message!\n\n",
		getMyLine()+1)
	c.Errorf("Error %v!", "message")
	failed := c.Failed()
	c.Succeed()
	if log := c.GetTestLog(); log != expectedLog {
		c.Logf("Errorf() logged %#v rather than %#v", log, expectedLog)
		c.Fail()
	}
	if !failed {
		c.Logf("Errorf() didn't put the test in a failed state")
		c.Fail()
	}
}
Beispiel #9
0
func (s *LegacySuite) checkTarContents(
	c *gc.C, tarFile io.Reader, allExpected []tarContent,
) {
	contents := readTarFile(c, tarFile)

	// Check that the expected entries are there.
	// XXX Check for unexpected entries.
	for _, expected := range allExpected {
		relPath := strings.TrimPrefix(expected.Name, string(os.PathSeparator))

		c.Log(fmt.Sprintf("checking for presence of %q on tar file", relPath))
		body, found := contents[relPath]
		if !found {
			c.Errorf("%q not found", expected.Name)
			continue
		}

		if expected.Body != "" {
			c.Log("Also checking the file contents")
			c.Check(body, gc.Equals, expected.Body)
		}

		if expected.Nested != nil {
			c.Log("Also checking the nested tar file")
			nestedFile := bytes.NewBufferString(body)
			s.checkTarContents(c, nestedFile, expected.Nested)
		}
	}

	if c.Failed() {
		c.Log("-----------------------")
		c.Log("expected:")
		for _, expected := range allExpected {
			c.Log(fmt.Sprintf("%s -> %q", expected.Name, expected.Body))
		}
		c.Log("got:")
		for name, body := range contents {
			if len(body) > 200 {
				body = body[:200] + "...(truncated)"
			}
			c.Log(fmt.Sprintf("%s -> %q", name, body))
		}
	}
}
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")
}
Beispiel #11
0
func (s *S) TestReadMetaline(c *check.C) {
	obtain := []interface{}{}
	if r, err := NewReaderName(G[1]); err != nil {
		c.Fatalf("Failed to open %q: %s", G[1], err)
	} else {
		r.TimeFormat = "Mon Jan _2 15:04:05 MST 2006"
		for i := 0; i < 3; i++ {
			for {
				if f, err := r.Read(); err != nil {
					if err == io.EOF {
						break
					} else {
						c.Fatalf("Failed to read %q: %s", G[1], err)
					}
				} else {
					obtain = append(obtain, f.Meta)
				}
			}
			if c.Failed() {
				break
			}
			if len(obtain) == len(expectMeta) {
				for j := range obtain {
					c.Check(obtain[j], check.DeepEquals, expectMeta[j])
				}
			} else {
				c.Check(len(obtain), check.Equals, len(expectMeta))
			}
			obtain = nil
			if err = r.Rewind(); err != nil {
				c.Fatalf("Failed to rewind %s", err)
			}
		}
		c.Check(r.SourceVersion, check.Equals, "<source> <version-text>")
		c.Check(r.Date.Format(r.TimeFormat), check.Equals, "Mon Jan  2 15:04:05 MST 2006")
		c.Check(r.Type, check.Equals, bio.Undefined)
		r.Close()
	}
}
Beispiel #12
0
func (s *S) TestReadBed(c *check.C) {
	obtain := []*feat.Feature{}
	for k, b := range B {
		if r, err := NewReaderName(b.bName, b.bType); err != nil {
			c.Fatalf("Failed to open %q: %s", b.bName, err)
		} else {
			for i := 0; i < 3; i++ {
				for {
					if f, err := r.Read(); err != nil {
						if err == io.EOF {
							break
						} else {
							c.Fatalf("Failed to read %q: %s", b.bName, err)
						}
					} else {
						obtain = append(obtain, f)
					}
				}
				if c.Failed() {
					break
				}
				if len(obtain) == len(expect[k]) {
					for j := range obtain {
						c.Check(*obtain[j], check.DeepEquals, expect[k][j])
					}
				} else {
					c.Log(k, b)
					c.Check(len(obtain), check.Equals, len(expect[k]))
				}
				if err = r.Rewind(); err != nil {
					c.Fatalf("Failed to Rewind: %s", err)
				}
				obtain = nil
			}
			r.Close()
		}
	}
}
Beispiel #13
0
// Verify the state of the test.  Note that since this also verifies if
// the test is supposed to be in a failed state, no other checks should
// be done in addition to what is being tested.
func checkState(c *gocheck.C, result interface{}, expected *expectedState) {
	failed := c.Failed()
	c.Succeed()
	log := c.GetTestLog()
	matched, matchError := regexp.MatchString("^"+expected.log+"$", log)
	if matchError != nil {
		c.Errorf("Error in matching expression used in testing %s",
			expected.name)
	} else if !matched {
		c.Errorf("%s logged %#v which doesn't match %#v",
			expected.name, log, expected.log)
	}
	if result != expected.result {
		c.Errorf("%s returned %#v rather than %#v",
			expected.name, result, expected.result)
	}
	if failed != expected.failed {
		if failed {
			c.Errorf("%s has failed when it shouldn't", expected.name)
		} else {
			c.Errorf("%s has not failed when it should", expected.name)
		}
	}
}
Beispiel #14
0
func (s *FastPeriodSuite) TestWatchCollection(c *gc.C) {
	chA1 := make(chan watcher.Change)
	chB1 := make(chan watcher.Change)
	chA := make(chan watcher.Change)
	chB := make(chan watcher.Change)

	s.w.Watch("testA", 1, -1, chA1)
	s.w.Watch("testB", 1, -1, chB1)
	s.w.WatchCollection("testA", chA)
	s.w.WatchCollection("testB", chB)

	revno1 := s.insert(c, "testA", 1)
	revno2 := s.insert(c, "testA", 2)
	revno3 := s.insert(c, "testB", 1)
	revno4 := s.insert(c, "testB", 2)

	s.w.StartSync()

	seen := map[chan<- watcher.Change][]watcher.Change{}
	timeout := time.After(testing.LongWait)
	n := 0
Loop1:
	for n < 6 {
		select {
		case chg := <-chA1:
			seen[chA1] = append(seen[chA1], chg)
		case chg := <-chB1:
			seen[chB1] = append(seen[chB1], chg)
		case chg := <-chA:
			seen[chA] = append(seen[chA], chg)
		case chg := <-chB:
			seen[chB] = append(seen[chB], chg)
		case <-timeout:
			break Loop1
		}
		n++
	}

	c.Check(seen[chA1], gc.DeepEquals, []watcher.Change{{"testA", 1, revno1}})
	c.Check(seen[chB1], gc.DeepEquals, []watcher.Change{{"testB", 1, revno3}})
	c.Check(seen[chA], gc.DeepEquals, []watcher.Change{{"testA", 1, revno1}, {"testA", 2, revno2}})
	c.Check(seen[chB], gc.DeepEquals, []watcher.Change{{"testB", 1, revno3}, {"testB", 2, revno4}})
	if c.Failed() {
		return
	}

	s.w.UnwatchCollection("testB", chB)
	s.w.Unwatch("testB", 1, chB1)

	revno1 = s.update(c, "testA", 1)
	revno3 = s.update(c, "testB", 1)

	s.w.StartSync()

	timeout = time.After(testing.LongWait)
	seen = map[chan<- watcher.Change][]watcher.Change{}
	n = 0
Loop2:
	for n < 2 {
		select {
		case chg := <-chA1:
			seen[chA1] = append(seen[chA1], chg)
		case chg := <-chB1:
			seen[chB1] = append(seen[chB1], chg)
		case chg := <-chA:
			seen[chA] = append(seen[chA], chg)
		case chg := <-chB:
			seen[chB] = append(seen[chB], chg)
		case <-timeout:
			break Loop2
		}
		n++
	}
	c.Check(seen[chA1], gc.DeepEquals, []watcher.Change{{"testA", 1, revno1}})
	c.Check(seen[chB1], gc.IsNil)
	c.Check(seen[chA], gc.DeepEquals, []watcher.Change{{"testA", 1, revno1}})
	c.Check(seen[chB], gc.IsNil)

	// Check that no extra events arrive.
	seen = map[chan<- watcher.Change][]watcher.Change{}
	timeout = time.After(testing.ShortWait)
Loop3:
	for {
		select {
		case chg := <-chA1:
			seen[chA1] = append(seen[chA1], chg)
		case chg := <-chB1:
			seen[chB1] = append(seen[chB1], chg)
		case chg := <-chA:
			seen[chA] = append(seen[chA], chg)
		case chg := <-chB:
			seen[chB] = append(seen[chB], chg)
		case <-timeout:
			break Loop3
		}
	}
	c.Check(seen[chA1], gc.IsNil)
	c.Check(seen[chB1], gc.IsNil)
	c.Check(seen[chA], gc.IsNil)
	c.Check(seen[chB], gc.IsNil)
}