本文整理汇总了Golang中github.com/stretchr/testify/require.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSpecOptInlineValue
func TestSpecOptInlineValue(t *testing.T) {
var f, g, x *string
var y *[]string
init := func(c *Cmd) {
f = c.StringOpt("f", "", "")
g = c.StringOpt("giraffe", "", "")
x = c.StringOpt("x", "", "")
y = c.StringsOpt("y", nil, "")
}
spec := "-x=<wolf-name> [ -f=<fish-name> | --giraffe=<giraffe-name> ] -y=<dog>..."
okCmd(t, spec, init, []string{"-x=a", "-y=b"})
require.Equal(t, "a", *x)
require.Equal(t, []string{"b"}, *y)
okCmd(t, spec, init, []string{"-x=a", "-y=b", "-y=c"})
require.Equal(t, "a", *x)
require.Equal(t, []string{"b", "c"}, *y)
okCmd(t, spec, init, []string{"-x=a", "-f=f", "-y=b"})
require.Equal(t, "a", *x)
require.Equal(t, "f", *f)
require.Equal(t, []string{"b"}, *y)
okCmd(t, spec, init, []string{"-x=a", "--giraffe=g", "-y=b"})
require.Equal(t, "a", *x)
require.Equal(t, "g", *g)
require.Equal(t, []string{"b"}, *y)
}
开发者ID:pki-io,项目名称:mow.cli,代码行数:29,代码来源:spec_n_parse_test.go
示例2: TestArtifactURL
func TestArtifactURL(t *testing.T) {
client := NewArtifactStoreClient("http://foo")
bucket := &Bucket{
bucket: &model.Bucket{
Id: "bkt",
},
client: client,
}
{
streamedArtifact := &StreamedArtifact{
ArtifactImpl: &ArtifactImpl{
artifact: &model.Artifact{
Name: "safct",
},
bucket: bucket,
},
}
require.Equal(t, "http://foo/buckets/bkt/artifacts/safct/content", streamedArtifact.GetContentURL())
}
{
chunkedArtifact := &ChunkedArtifact{
ArtifactImpl: &ArtifactImpl{
artifact: &model.Artifact{
Name: "cafct",
},
bucket: bucket,
},
}
require.Equal(t, "http://foo/buckets/bkt/artifacts/cafct/content", chunkedArtifact.GetContentURL())
}
}
开发者ID:dropbox,项目名称:changes-artifacts,代码行数:33,代码来源:client_unit_test.go
示例3: TestCollectAllSourceFilesFromFoldersWithSources
func TestCollectAllSourceFilesFromFoldersWithSources(t *testing.T) {
ctx := &types.Context{}
sourceFiles := &types.UniqueStringQueue{}
ctx.CollectedSourceFiles = sourceFiles
foldersWithSources := &types.UniqueSourceFolderQueue{}
foldersWithSources.Push(types.SourceFolder{Folder: Abs(t, "sketch_with_config"), Recurse: true})
ctx.FoldersWithSourceFiles = foldersWithSources
commands := []types.Command{
&builder.CollectAllSourceFilesFromFoldersWithSources{},
}
for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}
require.Equal(t, 1, len(*sourceFiles))
require.Equal(t, 0, len(*foldersWithSources))
sort.Strings(*sourceFiles)
require.Equal(t, Abs(t, filepath.Join("sketch_with_config", "includes", "de bug.cpp")), sourceFiles.Pop())
require.Equal(t, 0, len(*sourceFiles))
}
开发者ID:me-no-dev,项目名称:arduino-builder,代码行数:25,代码来源:collect_all_source_files_from_folders_with_sources_test.go
示例4: TestGetTrimmedStepName
func TestGetTrimmedStepName(t *testing.T) {
stepInfo := models.StepInfoModel{
ID: longStr,
Version: longStr,
}
result := models.StepRunResultsModel{
StepInfo: stepInfo,
Status: models.StepRunStatusCodeSuccess,
Idx: 0,
RunTime: 10000000,
Error: errors.New(longStr),
ExitCode: 1,
}
stepName := getTrimmedStepName(result)
require.Equal(t, "This is a very ... (...s a very long string.\n)", stepName)
stepInfo.ID = ""
result = models.StepRunResultsModel{
StepInfo: stepInfo,
Status: models.StepRunStatusCodeSuccess,
Idx: 0,
RunTime: 0,
Error: nil,
ExitCode: 0,
}
stepName = getTrimmedStepName(result)
require.Equal(t, " (...s a very long string.\n)", stepName)
}
开发者ID:bazscsa,项目名称:bitrise-cli,代码行数:31,代码来源:print_test.go
示例5: TestDonateSimple
func TestDonateSimple(t *testing.T) {
const (
testAddr1 = "10.0.1.0"
testAddr2 = "10.0.1.32"
size = 48
)
var (
ipAddr1 = ip(testAddr1)
)
ps1 := makeSpace(ipAddr1, size)
// Empty space set should split in two and give me the second half
r, ok := ps1.Donate(address.NewRange(ip(testAddr1), size))
numGivenUp := r.Size()
require.True(t, ok, "Donate result")
require.Equal(t, "10.0.1.24", r.Start.String(), "Invalid start")
require.Equal(t, address.Offset(size/2), numGivenUp)
require.Equal(t, address.Offset(size/2), ps1.NumFreeAddresses())
// Now check we can give the rest up.
count := 0 // count to avoid infinite loop
for ; count < 1000; count++ {
r, ok := ps1.Donate(address.NewRange(ip(testAddr1), size))
if !ok {
break
}
numGivenUp += r.Size()
}
require.Equal(t, address.Offset(0), ps1.NumFreeAddresses())
require.Equal(t, address.Offset(size), numGivenUp)
}
开发者ID:rahulxkrishna,项目名称:weave,代码行数:33,代码来源:space_test.go
示例6: TestMutlipleAdvertise
func TestMutlipleAdvertise(t *testing.T) {
runRetryTest(t, func(r *retryTest) {
r.mock.On("On", SendAdvertise).Return().
Times(1 /* initial */ + 10 /* successful retries */)
r.mock.On("On", Advertised).Return().Once()
r.setAdvertiseSuccess()
sc2, sc3 := r.ch.GetSubChannel("svc-2"), r.ch.GetSubChannel("svc-3")
require.NoError(t, r.client.Advertise(sc2, sc3))
// Verify that the arguments passed to 'ad' are correct.
expectedRequest := &AdRequest{[]service{
{Name: "my-client", Cost: 0},
{Name: "svc-2", Cost: 0},
{Name: "svc-3", Cost: 0},
}}
require.Equal(t, expectedRequest, r.req)
// Verify readvertise happen after sleeping for ~advertiseInterval.
r.mock.On("On", Readvertised).Return().Times(10)
for i := 0; i < 10; i++ {
s1 := <-r.sleepArgs
checkAdvertiseInterval(t, s1)
r.sleepBlock <- struct{}{}
r.setAdvertiseSuccess()
require.Equal(t, expectedRequest, r.req)
}
// Block till the last advertise completes.
<-r.sleepArgs
})
}
开发者ID:glycerine,项目名称:tchannel-go,代码行数:33,代码来源:advertise_test.go
示例7: TestGetGSResultFileLocations
func TestGetGSResultFileLocations(t *testing.T) {
testutils.SkipIfShort(t)
storage, err := storage.New(http.DefaultClient)
assert.Nil(t, err)
startTS := time.Date(2014, time.December, 10, 0, 0, 0, 0, time.UTC).Unix()
endTS := time.Date(2014, time.December, 10, 23, 59, 59, 0, time.UTC).Unix()
// TODO(stephana): Switch this to a dedicated test bucket, so we are not
// in danger of removing it.
resultFiles, err := getGSResultsFileLocations(startTS, endTS, storage, "chromium-skia-gm", "dm-json-v1")
assert.Nil(t, err)
// Read the expected list of files and compare them.
content, err := ioutil.ReadFile("./testdata/filelist_dec_10.txt")
assert.Nil(t, err)
lines := strings.Split(strings.TrimSpace(string(content)), "\n")
sort.Strings(lines)
resultNames := make([]string, len(resultFiles))
for idx, rf := range resultFiles {
resultNames[idx] = rf.Name
}
sort.Strings(resultNames)
assert.Equal(t, len(lines), len(resultNames))
assert.Equal(t, lines, resultNames)
}
开发者ID:Tiger66639,项目名称:skia-buildbot,代码行数:27,代码来源:ingester_test.go
示例8: TestStepResultCell
func TestStepResultCell(t *testing.T) {
result := models.StepRunResultsModel{
StepName: longStr,
Status: models.StepRunStatusCodeFailed,
Idx: 0,
RunTime: 10000000,
Error: errors.New(longStr),
ExitCode: 1,
}
cell := stepResultCell(result)
require.Equal(t, "| 🚫 | \x1b[31;1mThis is a very long string,\n... (exit code: 1)\x1b[0m| 0.01 sec |", cell)
result = models.StepRunResultsModel{
StepName: "",
Status: models.StepRunStatusCodeSuccess,
Idx: 0,
RunTime: 0,
Error: nil,
ExitCode: 0,
}
cell = stepResultCell(result)
require.Equal(t, "| ✅ | \x1b[32;1m\x1b[0m | 0.00 sec |", cell)
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:25,代码来源:print_test.go
示例9: TestTransformSections
func TestTransformSections(t *testing.T) {
assert.Equal(t, `<section class="section-class">
hello
</section>
`,
transformSections(`!section class="section-class"
hello
!/section
`))
// Test once through the full render function as well so that we can make
// sure that it still works even after content has been garbled by
// Markdown.
assert.Equal(t, `<section class="section-class">
<p>hello</p>
</section>
`,
Render(`!section class="section-class"
hello
!/section
`))
}
开发者ID:brandur,项目名称:singularity,代码行数:30,代码来源:markdown_test.go
示例10: TestSwizzlerSetThresholdBaseRole
// This sets the threshold for a base role
func TestSwizzlerSetThresholdBaseRole(t *testing.T) {
f, origMeta := createNewSwizzler(t)
f.SetThreshold(data.CanonicalTargetsRole, 3)
for role, metaBytes := range origMeta {
newMeta, err := f.MetadataCache.GetMeta(role, -1)
require.NoError(t, err)
// the threshold for base roles is set in root
if role != data.CanonicalRootRole {
require.True(t, bytes.Equal(metaBytes, newMeta), "bytes have changed for role %s", role)
} else {
require.False(t, bytes.Equal(metaBytes, newMeta))
signedRoot := &data.SignedRoot{}
require.NoError(t, json.Unmarshal(newMeta, signedRoot))
for r, roleInfo := range signedRoot.Signed.Roles {
if r != data.CanonicalTargetsRole {
require.Equal(t, 1, roleInfo.Threshold)
} else {
require.Equal(t, 3, roleInfo.Threshold)
}
}
}
}
}
开发者ID:moxiegirl,项目名称:notary,代码行数:27,代码来源:swizzler_test.go
示例11: TestGetTrimmedStepName
func TestGetTrimmedStepName(t *testing.T) {
result := models.StepRunResultsModel{
StepName: longStr,
Status: models.StepRunStatusCodeSuccess,
Idx: 0,
RunTime: 10000000,
Error: errors.New(longStr),
ExitCode: 1,
}
stepName := getTrimmedStepName(result)
require.Equal(t, "This is a very long string,\nthis is a very ...", stepName)
result = models.StepRunResultsModel{
StepName: "",
Status: models.StepRunStatusCodeSuccess,
Idx: 0,
RunTime: 0,
Error: nil,
ExitCode: 0,
}
stepName = getTrimmedStepName(result)
require.Equal(t, "", stepName)
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:25,代码来源:print_test.go
示例12: TestSwizzlerInvalidateMetadataSignatures
// This modifies the metadata so that the signed part has an extra, extraneous
// field. This does not prevent it from being unmarshalled as Signed* object,
// but the signature is no longer valid because the hash is different.
func TestSwizzlerInvalidateMetadataSignatures(t *testing.T) {
f, origMeta := createNewSwizzler(t)
f.InvalidateMetadataSignatures(data.CanonicalRootRole)
for role, metaBytes := range origMeta {
newMeta, err := f.MetadataCache.GetMeta(role, -1)
require.NoError(t, err)
if role != data.CanonicalRootRole {
require.True(t, bytes.Equal(metaBytes, newMeta), "bytes have changed for role %s", role)
} else {
require.False(t, bytes.Equal(metaBytes, newMeta))
// it be JSON unmarshallable into a data.Signed, and it's signed by
// root, but it is NOT the correct signature because the hash
// does not match
origSigned, newSigned := &data.Signed{}, &data.Signed{}
require.NoError(t, json.Unmarshal(metaBytes, origSigned))
require.NoError(t, json.Unmarshal(newMeta, newSigned))
require.Len(t, newSigned.Signatures, len(origSigned.Signatures))
for i := range origSigned.Signatures {
require.Equal(t, origSigned.Signatures[i].KeyID, newSigned.Signatures[i].KeyID)
require.Equal(t, origSigned.Signatures[i].Method, newSigned.Signatures[i].Method)
require.NotEqual(t, origSigned.Signatures[i].Signature, newSigned.Signatures[i].Signature)
require.Equal(t, []byte("invalid signature"), newSigned.Signatures[i].Signature)
}
require.True(t, bytes.Equal(origSigned.Signed, newSigned.Signed))
}
}
}
开发者ID:moxiegirl,项目名称:notary,代码行数:33,代码来源:swizzler_test.go
示例13: 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))
}
}
}
开发者ID:moxiegirl,项目名称:notary,代码行数:33,代码来源:swizzler_test.go
示例14: TestConnackDecodeEncodeEquiv
// test to ensure encoding and decoding are the same
// decode, encode, and decode again
func TestConnackDecodeEncodeEquiv(t *testing.T) {
msgBytes := []byte{
byte(CONNACK << 4),
2,
0, // session not present
0, // connection accepted
}
msg := NewConnackMessage()
n, err := msg.Decode(msgBytes)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n, "Error decoding message.")
dst := make([]byte, 100)
n2, err := msg.Encode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n2, "Error decoding message.")
require.Equal(t, msgBytes, dst[:n2], "Error decoding message.")
n3, err := msg.Decode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n3, "Error decoding message.")
}
开发者ID:XcoderAlex,项目名称:message,代码行数:28,代码来源:connack_test.go
示例15: TestFibonacciEMemoFunc
func TestFibonacciEMemoFunc(t *testing.T) {
calls := 0
fibonacci := NewEMemoFunc(
func(i int, f EMemoFunc) (interface{}, error) {
calls++
if i == 0 {
return uint64(0), nil
}
if i == 1 {
return uint64(1), nil
}
n1, err := f(i - 1)
if err != nil {
return 0, err
}
n2, err := f(i - 2)
if err != nil {
return 0, err
}
return n1.(uint64) + n2.(uint64), nil
},
)
result, err := fibonacci(93)
require.NoError(t, err)
require.Equal(t, uint64(12200160415121876738), result.(uint64))
require.Equal(t, 94, calls)
}
开发者ID:peter-edge,项目名称:pkg-go,代码行数:27,代码来源:pkgmemoize_test.go
示例16: TestPublishMessageEncode4
// test large message
func TestPublishMessageEncode4(t *testing.T) {
msgBytes := []byte{
byte(PUBLISH << 4),
137,
8,
0, // topic name MSB (0)
7, // topic name LSB (7)
's', 'u', 'r', 'g', 'e', 'm', 'q',
}
payload := make([]byte, 1024)
msgBytes = append(msgBytes, payload...)
msg := NewPublishMessage()
msg.Topic = []byte("surgemq")
msg.QoS = QosAtMostOnce
msg.Payload = payload
require.Equal(t, len(msgBytes), msg.Len())
dst := make([]byte, 1100)
n, err := msg.Encode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n, "Error decoding message.")
require.Equal(t, msgBytes, dst[:n], "Error decoding message.")
}
开发者ID:taoyonggang,项目名称:message,代码行数:28,代码来源:publish_test.go
示例17: TestGetStepIDStepDataPair
func TestGetStepIDStepDataPair(t *testing.T) {
stepData := stepmanModels.StepModel{}
t.Log("valid steplist item")
{
stepListItem := StepListItemModel{
"step1": stepData,
}
id, _, err := GetStepIDStepDataPair(stepListItem)
require.NoError(t, err)
require.Equal(t, "step1", id)
}
t.Log("invalid steplist item - more than 1 step")
{
stepListItem := StepListItemModel{
"step1": stepData,
"step2": stepData,
}
id, _, err := GetStepIDStepDataPair(stepListItem)
require.Error(t, err)
require.Equal(t, "", id)
}
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:26,代码来源:models_methods_test.go
示例18: TestPublishEqualDecodeEncode
func TestPublishEqualDecodeEncode(t *testing.T) {
msgBytes := []byte{
byte(PUBLISH<<4) | 2,
23,
0, // topic name MSB (0)
7, // topic name LSB (7)
's', 'u', 'r', 'g', 'e', 'm', 'q',
0, // packet ID MSB (0)
7, // packet ID LSB (7)
's', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e',
}
msg := NewPublishMessage()
n, err := msg.Decode(msgBytes)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n, "Error decoding message.")
dst := make([]byte, 100)
n2, err := msg.Encode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n2, "Error decoding message.")
require.Equal(t, msgBytes, dst[:n2], "Error decoding message.")
n3, err := msg.Decode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n3, "Error decoding message.")
}
开发者ID:taoyonggang,项目名称:message,代码行数:31,代码来源:publish_test.go
示例19: TestSubackEqualDecodeEncode
func TestSubackEqualDecodeEncode(t *testing.T) {
msgBytes := []byte{
byte(SUBACK << 4),
6,
0, // packet ID MSB (0)
7, // packet ID LSB (7)
0, // return code 1
1, // return code 2
2, // return code 3
0x80, // return code 4
}
msg := NewSubackMessage()
n, err := msg.Decode(msgBytes)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n, "Error decoding message.")
dst := make([]byte, 100)
n2, err := msg.Encode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n2, "Error decoding message.")
require.Equal(t, msgBytes, dst[:n2], "Error decoding message.")
n3, err := msg.Decode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n3, "Error decoding message.")
}
开发者ID:taoyonggang,项目名称:message,代码行数:30,代码来源:suback_test.go
示例20: TestPublishMessageEncode
func TestPublishMessageEncode(t *testing.T) {
msgBytes := []byte{
byte(PUBLISH<<4) | 2,
23,
0, // topic name MSB (0)
7, // topic name LSB (7)
's', 'u', 'r', 'g', 'e', 'm', 'q',
0, // packet ID MSB (0)
7, // packet ID LSB (7)
's', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e',
}
msg := NewPublishMessage()
msg.Topic = []byte("surgemq")
msg.QoS = QosAtLeastOnce
msg.PacketId = 7
msg.Payload = []byte{'s', 'e', 'n', 'd', ' ', 'm', 'e', ' ', 'h', 'o', 'm', 'e'}
dst := make([]byte, 100)
n, err := msg.Encode(dst)
require.NoError(t, err, "Error decoding message.")
require.Equal(t, len(msgBytes), n, "Error decoding message.")
require.Equal(t, msgBytes, dst[:n], "Error decoding message.")
}
开发者ID:taoyonggang,项目名称:message,代码行数:25,代码来源:publish_test.go
注:本文中的github.com/stretchr/testify/require.Equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论