本文整理汇总了Golang中github.com/stretchr/testify/require.True函数的典型用法代码示例。如果您正苦于以下问题:Golang True函数的具体用法?Golang True怎么用?Golang True使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了True函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPollAndExecOnceError
func TestPollAndExecOnceError(t *testing.T) {
task := pendingRecreateWebpageArchivesTask()
mockServer := frontend.MockServer{}
mockServer.SetCurrentTask(&task.RecreateWebpageArchivesDBTask)
defer frontend.CloseTestServer(frontend.InitTestServer(&mockServer))
commandCollector := exec.CommandCollector{}
mockRun := exec.MockRun{}
commandCollector.SetDelegateRun(mockRun.Run)
exec.SetRunForTesting(commandCollector.Run)
defer exec.SetRunForTesting(exec.DefaultRun)
mockRun.AddRule("capture_archives_on_workers", fmt.Errorf("workers too lazy"))
pollAndExecOnce()
// Expect only one poll.
expect.Equal(t, 1, mockServer.OldestPendingTaskReqCount())
// Expect three commands: git pull; make all; capture_archives_on_workers ...
commands := commandCollector.Commands()
assert.Len(t, commands, 3)
expect.Equal(t, "git pull", exec.DebugString(commands[0]))
expect.Equal(t, "make all", exec.DebugString(commands[1]))
expect.Equal(t, "capture_archives_on_workers", commands[2].Name)
// Expect an update marking task failed when command fails to execute.
assert.Len(t, mockServer.UpdateTaskReqs(), 1)
updateReq := mockServer.UpdateTaskReqs()[0]
assert.Equal(t, "/"+ctfeutil.UPDATE_RECREATE_WEBPAGE_ARCHIVES_TASK_POST_URI, updateReq.Url)
assert.NoError(t, updateReq.Error)
assert.False(t, updateReq.Vars.TsStarted.Valid)
assert.True(t, updateReq.Vars.TsCompleted.Valid)
assert.True(t, updateReq.Vars.Failure.Valid)
assert.True(t, updateReq.Vars.Failure.Bool)
assert.False(t, updateReq.Vars.RepeatAfterDays.Valid)
assert.Equal(t, int64(42), updateReq.Vars.Id)
}
示例2: TestDetectImagesContainerStopped
func TestDetectImagesContainerStopped(t *testing.T) {
manager, fakeRuntime, _ := newRealImageManager(ImageGCPolicy{})
fakeRuntime.ImageList = []container.Image{
makeImage(0, 1024),
makeImage(1, 2048),
}
fakeRuntime.AllPodList = []*container.Pod{
{
Containers: []*container.Container{
makeContainer(1),
},
},
}
err := manager.detectImages(zero)
assert := assert.New(t)
require.NoError(t, err)
assert.Equal(manager.imageRecordsLen(), 2)
withContainer, ok := manager.getImageRecord(imageName(1))
require.True(t, ok)
// Simulate container being stopped.
fakeRuntime.AllPodList = []*container.Pod{}
err = manager.detectImages(time.Now())
require.NoError(t, err)
assert.Equal(manager.imageRecordsLen(), 2)
container1, ok := manager.getImageRecord(imageName(0))
require.True(t, ok)
assert.Equal(zero, container1.firstDetected)
assert.Equal(zero, container1.lastUsed)
container2, ok := manager.getImageRecord(imageName(1))
require.True(t, ok)
assert.Equal(zero, container2.firstDetected)
assert.True(container2.lastUsed.Equal(withContainer.lastUsed))
}
示例3: testRasterizer
func testRasterizer(t *testing.T, rasterizer Rasterizer, expectation string) {
assert.True(t, rasterizer.Enabled(), "%s.Enabled() failed.", rasterizer.String())
testDataDir, err := testutils.TestDataDir()
assert.Nil(t, err, "TestDataDir missing: %v", err)
tempDir, err := ioutil.TempDir("", "pdf_test_")
assert.Nil(t, err, "ioutil.TempDir failed")
defer util.RemoveAll(tempDir)
pdfSrcPath := path.Join(testDataDir, "minimal.pdf")
assert.True(t, fileutil.FileExists(pdfSrcPath), "Path '%s' does not exist", pdfSrcPath)
pdfInputPath := path.Join(tempDir, "minimal.pdf")
err = os.Symlink(pdfSrcPath, pdfInputPath)
assert.Nil(t, err, "Symlink failed")
assert.True(t, fileutil.FileExists(pdfInputPath), "Path '%s' does not exist", pdfInputPath)
outputFileName := path.Join(tempDir, "test.png")
badPath := path.Join(tempDir, "this_file_should_really_not_exist.pdf")
if err := rasterizer.Rasterize(badPath, outputFileName); err == nil {
t.Errorf(": Got '%v' Want '%v'", err, nil)
}
if err := rasterizer.Rasterize(pdfInputPath, outputFileName); err != nil {
t.Errorf(": Got '%v' Want '!nil'", err)
}
expectedOutput := path.Join(testDataDir, expectation)
assert.True(t, filesEqual(outputFileName, expectedOutput), "png output not correct")
}
示例4: TestSwizzlerAddExtraSpace
// This adds a single byte of whitespace to the metadata file, so it should be parsed
// and deserialized the same way, but checksums against snapshot/timestamp may fail
func TestSwizzlerAddExtraSpace(t *testing.T) {
f, origMeta := createNewSwizzler(t)
f.AddExtraSpace(data.CanonicalTargetsRole)
snapshot := &data.SignedSnapshot{}
require.NoError(t, json.Unmarshal(origMeta[data.CanonicalSnapshotRole], snapshot))
for role, metaBytes := range origMeta {
newMeta, err := f.MetadataCache.GetMeta(role, -1)
require.NoError(t, err)
if role != data.CanonicalTargetsRole {
require.True(t, bytes.Equal(metaBytes, newMeta), "bytes have changed for role %s", role)
} else {
require.False(t, bytes.Equal(metaBytes, newMeta))
require.True(t, bytes.Equal(metaBytes, newMeta[1:len(metaBytes)+1]))
require.Equal(t, byte(' '), newMeta[0])
require.Equal(t, byte(' '), newMeta[len(newMeta)-1])
// make sure the hash is not the same as the hash in snapshot
newHash := sha256.Sum256(newMeta)
require.False(t, bytes.Equal(
snapshot.Signed.Meta[data.CanonicalTargetsRole].Hashes["sha256"],
newHash[:]))
require.NotEqual(t,
snapshot.Signed.Meta[data.CanonicalTargetsRole].Length,
len(newMeta))
}
}
}
示例5: TestTransfer
func TestTransfer(t *testing.T) {
const (
cidr = "10.0.1.7/22"
)
allocs, router, subnet := makeNetworkOfAllocators(3, cidr)
alloc1 := allocs[0]
alloc2 := allocs[1]
alloc3 := allocs[2] // This will be 'master' and get the first range
_, err := alloc2.Allocate("foo", subnet, nil)
require.True(t, err == nil, "Failed to get address")
_, err = alloc3.Allocate("bar", subnet, nil)
require.True(t, err == nil, "Failed to get address")
router.GossipBroadcast(alloc2.Gossip())
router.Flush()
router.GossipBroadcast(alloc3.Gossip())
router.Flush()
router.RemovePeer(alloc2.ourName)
router.RemovePeer(alloc3.ourName)
alloc2.Stop()
alloc3.Stop()
router.Flush()
require.NoError(t, alloc1.AdminTakeoverRanges(alloc2.ourName.String()))
require.NoError(t, alloc1.AdminTakeoverRanges(alloc3.ourName.String()))
router.Flush()
require.Equal(t, address.Offset(1022), alloc1.NumFreeAddresses(subnet))
_, err = alloc1.Allocate("foo", subnet, nil)
require.True(t, err == nil, "Failed to get address")
alloc1.Stop()
}
示例6: TestSpecOptionalOption3Choice
func TestSpecOptionalOption3Choice(t *testing.T) {
var f, g, h *bool
init := func(c *Cmd) {
f = c.BoolOpt("f", false, "")
g = c.BoolOpt("g", false, "")
h = c.BoolOpt("x", false, "")
}
spec := "[-f|-g|-x]"
okCmd(t, spec, init, []string{})
require.False(t, *f)
require.False(t, *g)
require.False(t, *h)
okCmd(t, spec, init, []string{"-f"})
require.True(t, *f)
require.False(t, *g)
require.False(t, *h)
okCmd(t, spec, init, []string{"-g"})
require.False(t, *f)
require.True(t, *g)
require.False(t, *h)
okCmd(t, spec, init, []string{"-x"})
require.False(t, *f)
require.False(t, *g)
require.True(t, *h)
}
示例7: TestSpecSingleDash
func TestSpecSingleDash(t *testing.T) {
var path *string
var f *bool
init := func(c *Cmd) {
path = c.StringArg("PATH", "", "'-' can be used to read from stdin' ")
f = c.BoolOpt("f", false, "")
}
spec := "[-f] PATH"
okCmd(t, spec, init, []string{"TEST"})
require.Equal(t, "TEST", *path)
require.False(t, *f)
okCmd(t, spec, init, []string{"-f", "TEST"})
require.Equal(t, "TEST", *path)
require.True(t, *f)
okCmd(t, spec, init, []string{"-"})
require.Equal(t, "-", *path)
require.False(t, *f)
okCmd(t, spec, init, []string{"-f", "-"})
require.Equal(t, "-", *path)
require.True(t, *f)
okCmd(t, spec, init, []string{"--", "-"})
require.Equal(t, "-", *path)
require.False(t, *f)
okCmd(t, spec, init, []string{"-f", "--", "-"})
require.Equal(t, "-", *path)
require.True(t, *f)
}
示例8: TestDataKey
func TestDataKey(t *testing.T) {
var uid uint64
for uid = 0; uid < 1001; uid++ {
sattr := fmt.Sprintf("attr:%d", uid)
key := DataKey(sattr, uid)
pk := Parse(key)
require.True(t, pk.IsData())
require.Equal(t, sattr, pk.Attr)
require.Equal(t, uid, pk.Uid)
}
keys := make([]string, 0, 1024)
for uid = 1024; uid >= 1; uid-- {
key := DataKey("testing.key", uid)
keys = append(keys, string(key))
}
// Test that sorting is as expected.
sort.Strings(keys)
require.True(t, sort.StringsAreSorted(keys))
for i, key := range keys {
exp := DataKey("testing.key", uint64(i+1))
require.Equal(t, string(exp), key)
}
}
示例9: TestSpaceFree
func TestSpaceFree(t *testing.T) {
const (
testAddr1 = "10.0.3.16"
testAddrx = "10.0.3.19"
testAddry = "10.0.9.19"
containerID = "deadbeef"
size = 16
)
entireRange := address.NewRange(ip(testAddr1), size)
space := makeSpace(ip(testAddr1), size)
// Check we are prepared to give up the entire space
r := space.biggestFreeRange(entireRange)
require.Equal(t, address.NewRange(ip(testAddr1), size), r, "Wrong space")
for i := 0; i < size; i++ {
ok, _ := space.Allocate(entireRange)
require.True(t, ok, "Failed to get address")
}
// Check we are full
ok, _ := space.Allocate(entireRange)
require.True(t, !ok, "Should have failed to get address")
r, _ = space.Donate(entireRange)
require.True(t, r.Size() == 0, "Wrong space")
// Free in the middle
require.NoError(t, space.Free(ip("10.0.3.23")))
r = space.biggestFreeRange(entireRange)
require.True(t, r.Start == ip("10.0.3.23") && r.Size() == 1, "Wrong space")
// Free one at the end
require.NoError(t, space.Free(ip("10.0.3.31")))
r = space.biggestFreeRange(entireRange)
require.True(t, r.Start == ip("10.0.3.31") && r.Size() == 1, "Wrong space")
// Now free a few at the end
require.NoError(t, space.Free(ip("10.0.3.30")))
require.NoError(t, space.Free(ip("10.0.3.29")))
require.Equal(t, address.Count(4), space.NumFreeAddresses())
// Now get the biggest free space; should be 3.30
r = space.biggestFreeRange(entireRange)
require.Equal(t, address.NewRange(ip("10.0.3.30"), 2), r, "Wrong space")
// Now free a few in the middle
require.NoError(t, space.Free(ip("10.0.3.24")))
require.NoError(t, space.Free(ip("10.0.3.22")))
require.NoError(t, space.Free(ip("10.0.3.21")))
require.Equal(t, address.Count(7), space.NumFreeAddresses())
// Now get the biggest free space; should be 3.30
r = space.biggestFreeRange(entireRange)
require.Equal(t, address.NewRange(ip("10.0.3.30"), 2), r, "Wrong space")
require.Equal(t, []address.Range{{Start: ip("10.0.3.16"), End: ip("10.0.3.32")}}, space.OwnedRanges())
}
示例10: TestMatchesFilterIntersectsPoint
func TestMatchesFilterIntersectsPoint(t *testing.T) {
p := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-122.082506, 37.4249518})
data := formDataPoint(t, p)
_, qd, err := queryTokens(QueryTypeIntersects, data, 0.0)
require.NoError(t, err)
// Same point
p2 := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-122.082506, 37.4249518})
require.True(t, qd.MatchesFilter(types.Geo{p2}))
// Different point
p3 := geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{-123.082506, 37.4249518})
require.False(t, qd.MatchesFilter(types.Geo{p3}))
// containing poly
poly := geom.NewPolygon(geom.XY).MustSetCoords([][]geom.Coord{
{{-122, 37}, {-123, 37}, {-123, 38}, {-122, 38}, {-122, 37}},
})
require.True(t, qd.MatchesFilter(types.Geo{poly}))
// Polygon doesn't contains
poly = geom.NewPolygon(geom.XY).MustSetCoords([][]geom.Coord{
{{-122, 36}, {-123, 36}, {-123, 37}, {-122, 37}, {-122, 36}},
})
require.False(t, qd.MatchesFilter(types.Geo{poly}))
}
示例11: TestMergeErrors
func TestMergeErrors(t *testing.T) {
// Cannot Merge in an invalid ring
ring1 := New(start, end, peer1name)
ring2 := New(start, end, peer2name)
ring2.Entries = []*entry{{Token: middle, Peer: peer2name}, {Token: start, Peer: peer2name}}
require.True(t, ring1.Merge(*ring2) == ErrNotSorted, "Expected ErrNotSorted")
// Should Merge two rings for different ranges
ring2 = New(start, middle, peer2name)
ring2.Entries = []*entry{}
require.True(t, ring1.Merge(*ring2) == ErrDifferentSubnets, "Expected ErrDifferentSubnets")
// Cannot Merge newer version of entry I own
ring2 = New(start, end, peer2name)
ring1.Entries = []*entry{{Token: start, Peer: peer1name}}
ring2.Entries = []*entry{{Token: start, Peer: peer1name, Version: 1}}
require.True(t, ring1.Merge(*ring2) == ErrNewerVersion, "Expected ErrNewerVersion")
// Cannot Merge two entries with same version but different hosts
ring1.Entries = []*entry{{Token: start, Peer: peer1name}}
ring2.Entries = []*entry{{Token: start, Peer: peer2name}}
require.True(t, ring1.Merge(*ring2) == ErrInvalidEntry, "Expected ErrInvalidEntry")
// Cannot Merge an entry into a range I own
ring1.Entries = []*entry{{Token: start, Peer: peer1name}}
ring2.Entries = []*entry{{Token: middle, Peer: peer2name}}
require.True(t, ring1.Merge(*ring2) == ErrEntryInMyRange, "Expected ErrEntryInMyRange")
}
示例12: TestCryDifferentLocations
func TestCryDifferentLocations(t *testing.T) {
require.True(t, CryHeard())
require.True(t, CryHeard())
require.True(t, CryHeard())
require.True(t, CryHeard())
require.True(t, CryHeard())
}
示例13: TestByteConversion
func TestByteConversion(t *testing.T) {
numbers32 := []uint32{5251, uint32Max, 0, 1, 101, 2387, 219}
for _, i := range numbers32 {
data, err := uint32ToBytes(i)
require.NoError(t, err)
require.Len(t, data, 4)
ii, err := bytesToUint32(data)
require.NoError(t, err)
require.True(t, ii == i)
}
numbers16 := []uint16{5251, uint16Max, 0, 1, 101, 2387, 219}
for _, i := range numbers16 {
data, err := uint16ToBytes(i)
require.NoError(t, err)
require.Len(t, data, 2)
ii, err := bytesToUint16(data)
require.NoError(t, err)
require.True(t, ii == i)
}
}
示例14: TestSetupBuildProperties
func TestSetupBuildProperties(t *testing.T) {
DownloadCoresAndToolsAndLibraries(t)
ctx := &types.Context{
HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "user_hardware"},
ToolsFolders: []string{"downloaded_tools", "./tools_builtin"},
SketchLocation: filepath.Join("sketch1", "sketch.ino"),
FQBN: "arduino:avr:uno",
ArduinoAPIVersion: "10600",
}
buildPath := SetupBuildPath(t, ctx)
defer os.RemoveAll(buildPath)
commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
&builder.HardwareLoader{},
&builder.ToolsLoader{},
&builder.TargetBoardResolver{},
&builder.SketchLoader{},
&builder.SetupBuildProperties{},
}
for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}
buildProperties := ctx.BuildProperties
require.Equal(t, "ARDUINO", buildProperties[constants.BUILD_PROPERTIES_SOFTWARE])
require.Equal(t, "uno", buildProperties[constants.ID])
require.Equal(t, "Arduino/Genuino Uno", buildProperties["name"])
require.Equal(t, "0x2341", buildProperties["vid.0"])
require.Equal(t, "\"{compiler.path}{compiler.c.cmd}\" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} \"{source_file}\" -o \"{object_file}\"", buildProperties["recipe.c.o.pattern"])
require.Equal(t, "{path}/etc/avrdude.conf", buildProperties["tools.avrdude.config.path"])
require.Equal(t, Abs(t, "downloaded_hardware/arduino/avr"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH])
require.Equal(t, Abs(t, "downloaded_hardware/arduino"), buildProperties[constants.BUILD_PROPERTIES_RUNTIME_HARDWARE_PATH])
require.Equal(t, "10600", buildProperties[constants.BUILD_PROPERTIES_RUNTIME_IDE_VERSION])
require.NotEmpty(t, buildProperties[constants.BUILD_PROPERTIES_RUNTIME_OS])
require.Equal(t, Abs(t, "./downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1"), buildProperties["runtime.tools.arm-none-eabi-gcc.path"])
require.Equal(t, Abs(t, "./downloaded_tools/arm-none-eabi-gcc/4.8.3-2014q1"), buildProperties["runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path"])
require.Equal(t, Abs(t, "./downloaded_tools/bossac/1.6.1-arduino"), buildProperties["runtime.tools.bossac-1.6.1-arduino.path"])
require.Equal(t, Abs(t, "./downloaded_tools/bossac/1.5-arduino"), buildProperties["runtime.tools.bossac-1.5-arduino.path"])
require.True(t, buildProperties["runtime.tools.bossac.path"] == Abs(t, "./downloaded_tools/bossac/1.6.1-arduino") || buildProperties["runtime.tools.bossac.path"] == Abs(t, "./downloaded_tools/bossac/1.5-arduino"))
require.Equal(t, Abs(t, "./downloaded_tools/avrdude/6.0.1-arduino5"), buildProperties["runtime.tools.avrdude.path"])
require.Equal(t, Abs(t, "./downloaded_tools/avrdude/6.0.1-arduino5"), buildProperties["runtime.tools.avrdude-6.0.1-arduino5.path"])
require.Equal(t, Abs(t, "./downloaded_tools/avr-gcc/4.8.1-arduino5"), buildProperties["runtime.tools.avr-gcc.path"])
require.Equal(t, Abs(t, "./downloaded_tools/avr-gcc/4.8.1-arduino5"), buildProperties["runtime.tools.avr-gcc-4.8.1-arduino5.path"])
require.Equal(t, Abs(t, "sketch1"), buildProperties[constants.BUILD_PROPERTIES_SOURCE_PATH])
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_UTC))
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_LOCAL))
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_ZONE))
require.True(t, utils.MapStringStringHas(buildProperties, constants.BUILD_PROPERTIES_EXTRA_TIME_DST))
}
示例15: TestParseTLSWithEnvironmentVariables
func TestParseTLSWithEnvironmentVariables(t *testing.T) {
config := configure(fmt.Sprintf(`{
"server": {
"tls_cert_file": "%s",
"client_ca_file": "nosuchfile"
}
}`, Cert))
vars := map[string]string{
"SERVER_TLS_KEY_FILE": Key,
"SERVER_CLIENT_CA_FILE": Root,
}
setupEnvironmentVariables(t, vars)
defer cleanupEnvironmentVariables(t, vars)
tlsConfig, err := ParseServerTLS(config, true)
require.NoError(t, err)
expectedCert, err := tls.LoadX509KeyPair(Cert, Key)
require.NoError(t, err)
expectedRoot, err := trustmanager.LoadCertFromFile(Root)
require.NoError(t, err)
require.Len(t, tlsConfig.Certificates, 1)
require.True(t, reflect.DeepEqual(expectedCert, tlsConfig.Certificates[0]))
subjects := tlsConfig.ClientCAs.Subjects()
require.Len(t, subjects, 1)
require.True(t, bytes.Equal(expectedRoot.RawSubject, subjects[0]))
require.Equal(t, tlsConfig.ClientAuth, tls.RequireAndVerifyClientCert)
}