本文整理汇总了Golang中github.com/stretchr/testify/assert.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestClient_sendError
func TestClient_sendError(t *testing.T) {
client := &client{
httpClient: &http.Client{
Timeout: time.Second * 2,
},
}
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(&Response{
Jsonrpc: "2.0",
RequestID: 42,
Error: &Error{
Code: InternalError,
Message: Errors[InternalError],
},
})
}))
defer testServer.Close()
if err := client.send(testServer.URL, []byte{}, nil); assert.Error(t, err) {
assert.Equal(t, errorFmt(InternalError, Errors[InternalError]).Error(), err.Error())
}
if err := client.send("http://dev.null", []byte{}, nil); assert.Error(t, err) {
assert.Contains(t, err.Error(), "dev.null")
}
}
开发者ID:kshvakov,项目名称:jsonrpc2,代码行数:32,代码来源:client_test.go
示例2: TestUploadFailCleanup
func TestUploadFailCleanup(t *testing.T) {
svc := s3.New(nil)
// Break checksum on 2nd part so it fails
part := 0
svc.Handlers.Build.PushBack(func(r *request.Request) {
if r.Operation.Name == "UploadPart" {
if part == 1 {
r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", "000")
}
part++
}
})
key := "12mb-leave"
mgr := s3manager.NewUploader(&s3manager.UploadOptions{
S3: svc,
LeavePartsOnError: false,
})
_, err := mgr.Upload(&s3manager.UploadInput{
Bucket: bucketName,
Key: &key,
Body: bytes.NewReader(integBuf12MB),
})
assert.Error(t, err)
uploadID := ""
if merr, ok := err.(s3manager.MultiUploadFailure); ok {
uploadID = merr.UploadID()
}
assert.NotEmpty(t, uploadID)
_, err = svc.ListParts(&s3.ListPartsInput{
Bucket: bucketName, Key: &key, UploadId: &uploadID})
assert.Error(t, err)
}
开发者ID:jloper3,项目名称:amazon-ecs-cli,代码行数:35,代码来源:integration_test.go
示例3: TestAggregateMetricsError
// TestAggregateMetricsError tests the error flows of aggregateMetrics.
func TestAggregateMetricsError(t *testing.T) {
var (
model = newRealModel(time.Minute)
targetInfo = InfoType{
Metrics: make(map[string]*daystore.DayStore),
Labels: make(map[string]string),
}
srcInfo = InfoType{
Metrics: make(map[string]*daystore.DayStore),
Labels: make(map[string]string),
}
assert = assert.New(t)
)
// Invocation with nil first argument
sources := []*InfoType{&srcInfo}
assert.Error(model.aggregateMetrics(nil, sources, time.Now()))
// Invocation with empty second argument
sources = []*InfoType{}
assert.Error(model.aggregateMetrics(&targetInfo, sources, time.Now()))
// Invocation with a nil element in the second argument
sources = []*InfoType{&srcInfo, nil}
assert.Error(model.aggregateMetrics(&targetInfo, sources, time.Now()))
// Invocation with the target being also part of sources
sources = []*InfoType{&srcInfo, &targetInfo}
assert.Error(model.aggregateMetrics(&targetInfo, sources, time.Now()))
// Normal Invocation with latestTime being zero
sources = []*InfoType{&srcInfo}
assert.Error(model.aggregateMetrics(&targetInfo, sources, time.Time{}))
}
开发者ID:MohamedFAhmed,项目名称:heapster,代码行数:35,代码来源:aggregation_test.go
示例4: TestPlaceContainerHuge
func TestPlaceContainerHuge(t *testing.T) {
s := &BinPackingPlacementStrategy{}
nodes := []*cluster.Node{}
for i := 0; i < 100; i++ {
nodes = append(nodes, createNode(fmt.Sprintf("node-%d", i), 1, 1))
}
// add 100 container 1CPU
for i := 0; i < 100; i++ {
node, err := s.PlaceContainer(createConfig(0, 1), nodes)
assert.NoError(t, err)
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), createConfig(0, 100))))
}
// try to add another container 1CPU
_, err := s.PlaceContainer(createConfig(0, 1), nodes)
assert.Error(t, err)
// add 100 container 1G
for i := 100; i < 200; i++ {
node, err := s.PlaceContainer(createConfig(1, 0), nodes)
assert.NoError(t, err)
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), createConfig(1, 0))))
}
// try to add another container 1G
_, err = s.PlaceContainer(createConfig(1, 0), nodes)
assert.Error(t, err)
}
开发者ID:SivagnanamCiena,项目名称:swarm,代码行数:30,代码来源:binpacking_test.go
示例5: cas
func cas(t *testing.T) {
fmt.Println("cas")
kv := kvdb.Instance()
assert.NotNil(t, kv, "Default KVDB is not set")
key := "foo/docker"
val := "great"
defer func() {
kv.Delete(key)
}()
kvPair, err := kv.Put(key, []byte(val), 10)
assert.NoError(t, err, "Unxpected error in Put")
kvPair, err = kv.Get(key)
assert.NoError(t, err, "Failed in Get")
_, err = kv.CompareAndSet(kvPair, kvdb.KVFlags(0), []byte("badval"))
assert.Error(t, err, "CompareAndSet should fail on an incorrect previous value")
kvPair.ModifiedIndex++
_, err = kv.CompareAndSet(kvPair, kvdb.KVModifiedIndex, nil)
assert.Error(t, err, "CompareAndSet should fail on an incorrect modified index")
kvPair.ModifiedIndex--
kvPair, err = kv.CompareAndSet(kvPair, kvdb.KVModifiedIndex, nil)
assert.NoError(t, err, "CompareAndSet should succeed on an correct modified index")
kvPair, err = kv.CompareAndSet(kvPair, kvdb.KVFlags(0), []byte(val))
assert.NoError(t, err, "CompareAndSet should succeed on an correct value")
kvPair, err = kv.CompareAndSet(kvPair, kvdb.KVModifiedIndex, []byte(val))
assert.NoError(t, err, "CompareAndSet should succeed on an correct value and modified index")
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:34,代码来源:kv.go
示例6: TestSubVolumeCreateValidation
func TestSubVolumeCreateValidation(t *testing.T) {
subvol := btrfs.NewIoctl().Subvolume()
cmd := subvol.Create()
err := cmd.Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "destination is empty")
cmd = subvol.Create()
err = cmd.Destination(strings.Repeat("s", 512)).Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "subvolume name too long")
assert.Contains(t, err.Error(), "max length is 255")
// cmd = subvol.Create()
// err = cmd.Name("/name").Execute()
// assert.Error(t, err)
// assert.Contains(t, err.Error(), "incorrect subvolume name '/name'")
cmd = subvol.Create()
err = cmd.Destination(".").Execute()
assert.Contains(t, err.Error(), "incorrect subvolume name '.'")
cmd = subvol.Create()
err = cmd.Destination("..").Execute()
assert.Error(t, err)
assert.Contains(t, err.Error(), "incorrect subvolume name '..'")
}
开发者ID:plar,项目名称:btrfs,代码行数:27,代码来源:subvolume_test.go
示例7: TestValidateCredentialsHandlerError
func TestValidateCredentialsHandlerError(t *testing.T) {
os.Clearenv()
creds, _ := ProfileCreds("example.ini", "missing", 10*time.Minute)
svc := NewService(&Config{Credentials: creds})
svc.Handlers.Clear()
svc.Handlers.Validate.PushBack(ValidateCredentialsHandler)
req := NewRequest(svc, &Operation{Name: "Operation"}, nil, nil)
err := req.Build()
assert.Error(t, err)
assert.Equal(t, ErrMissingCredentials, err)
// Now try without any credentials object at all
svc = NewService(nil)
svc.Handlers.Clear()
svc.Handlers.Validate.PushBack(ValidateCredentialsHandler)
req = NewRequest(svc, &Operation{Name: "Operation"}, nil, nil)
err = req.Build()
assert.Error(t, err)
assert.Equal(t, ErrMissingCredentials, err)
}
开发者ID:dockerstack,项目名称:amazon-ecs-agent,代码行数:25,代码来源:handler_functions_test.go
示例8: TestGetFCNetworks
func TestGetFCNetworks(t *testing.T) {
var (
c *OVClient
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA("test_fc_network")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
fcNetworks, err := c.GetFCNetworks("", "")
assert.NoError(t, err, "GetFCNetworks threw an error -> %s. %+v\n", err, fcNetworks)
fcNetworks, err = c.GetFCNetworks("", "name:asc")
assert.NoError(t, err, "GetFCNetworks name:asc error -> %s. %+v\n", err, fcNetworks)
} else {
_, c = getTestDriverU("test_fc_network")
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
data, err := c.GetFCNetworks("", "")
assert.Error(t, err, fmt.Sprintf("All OK, no error, caught as expected: %s,%+v\n", err, data))
}
_, c = getTestDriverU("test_fc_network")
data, err := c.GetProfiles("", "")
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
}
开发者ID:wenlock,项目名称:oneview-golang,代码行数:29,代码来源:fc_network_test.go
示例9: TestUploadMultipart
func TestUploadMultipart(t *testing.T) {
assert := assert.New(t)
var body bytes.Buffer
mw := multipart.NewWriter(&body)
if err := writeMPBody("../dummy/32509211_news_bigpic.jpg", mw); err != nil {
assert.Error(err)
}
if err := writeMPBody("../dummy/kino.jpg", mw); err != nil {
assert.Error(err)
}
mw.Close()
req, _ := http.NewRequest("POST", "/files", &body)
req.Header.Set("Content-Type", mw.FormDataContentType())
req.AddCookie(&http.Cookie{Name: "pavo", Value: "abcdef"})
files, err := Process(req, "../dummy/root_storage")
assert.Nil(err)
assert.Equal("kino.jpg", files[1].Filename)
assert.Equal("image", files[1].BaseMime)
}
开发者ID:rd-2bees,项目名称:docker,代码行数:25,代码来源:upload_test.go
示例10: TestRemoveUnusedSecret
func TestRemoveUnusedSecret(t *testing.T) {
ts := newTestServer(t)
defer ts.Stop()
// removing a secret without providing an ID results in an InvalidArgument
_, err := ts.Client.RemoveSecret(context.Background(), &api.RemoveSecretRequest{})
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, grpc.Code(err), grpc.ErrorDesc(err))
// removing a secret that exists succeeds
secret := secretFromSecretSpec(createSecretSpec("name", []byte("data"), nil))
err = ts.Store.Update(func(tx store.Tx) error {
return store.CreateSecret(tx, secret)
})
assert.NoError(t, err)
resp, err := ts.Client.RemoveSecret(context.Background(), &api.RemoveSecretRequest{SecretID: secret.ID})
assert.NoError(t, err)
assert.Equal(t, api.RemoveSecretResponse{}, *resp)
// ---- it was really removed because attempting to remove it again fails with a NotFound ----
_, err = ts.Client.RemoveSecret(context.Background(), &api.RemoveSecretRequest{SecretID: secret.ID})
assert.Error(t, err)
assert.Equal(t, codes.NotFound, grpc.Code(err), grpc.ErrorDesc(err))
}
开发者ID:docker,项目名称:swarmkit,代码行数:26,代码来源:secret_test.go
示例11: TestYubiImportNonRootKey
// Importing a key not as root fails, and it is not added to the backup store
func TestYubiImportNonRootKey(t *testing.T) {
if !YubikeyAccessible() {
t.Skip("Must have Yubikey access.")
}
clearAllKeys(t)
SetYubikeyKeyMode(KeymodeNone)
defer func() {
SetYubikeyKeyMode(KeymodeTouch | KeymodePinOnce)
}()
backup := trustmanager.NewKeyMemoryStore(ret)
store, err := NewYubiKeyStore(backup, ret)
assert.NoError(t, err)
// generate key and import it
privKey, err := trustmanager.GenerateECDSAKey(rand.Reader)
assert.NoError(t, err)
pemBytes, err := trustmanager.EncryptPrivateKey(privKey, "passphrase")
assert.NoError(t, err)
err = store.ImportKey(pemBytes, privKey.ID())
assert.Error(t, err)
// key is not in backup store
_, _, err = backup.GetKey(privKey.ID())
assert.Error(t, err)
}
开发者ID:runcom,项目名称:notary,代码行数:30,代码来源:yubikeystore_test.go
示例12: TestGetSecret
func TestGetSecret(t *testing.T) {
ts := newTestServer(t)
defer ts.Stop()
// ---- getting a secret without providing an ID results in an InvalidArgument ----
_, err := ts.Client.GetSecret(context.Background(), &api.GetSecretRequest{})
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, grpc.Code(err), grpc.ErrorDesc(err))
// ---- getting a non-existent secret fails with NotFound ----
_, err = ts.Client.GetSecret(context.Background(), &api.GetSecretRequest{SecretID: "12345"})
assert.Error(t, err)
assert.Equal(t, codes.NotFound, grpc.Code(err), grpc.ErrorDesc(err))
// ---- getting an existing secret returns the secret with all the private data cleaned ----
secret := secretFromSecretSpec(createSecretSpec("name", []byte("data"), nil))
err = ts.Store.Update(func(tx store.Tx) error {
return store.CreateSecret(tx, secret)
})
assert.NoError(t, err)
resp, err := ts.Client.GetSecret(context.Background(), &api.GetSecretRequest{SecretID: secret.ID})
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.NotNil(t, resp.Secret)
// the data should be empty/omitted
assert.NotEqual(t, secret, resp.Secret)
secret.Spec.Data = nil
assert.Equal(t, secret, resp.Secret)
}
开发者ID:docker,项目名称:swarmkit,代码行数:31,代码来源:secret_test.go
示例13: TestUPIDParse
func TestUPIDParse(t *testing.T) {
u, err := Parse("[email protected]:bar")
assert.Nil(t, u)
assert.Error(t, err)
u, err = Parse("mesoslocalhost5050")
assert.Nil(t, u)
assert.Error(t, err)
u, err = Parse("[email protected]")
assert.Nil(t, u)
assert.Error(t, err)
// Simple fuzzy test.
for i := 0; i < 100000; i++ {
ra := generateRandomString()
u, err = Parse(ra)
if u != nil {
println(ra)
}
assert.Nil(t, u)
assert.Error(t, err)
}
}
开发者ID:nagyistoce,项目名称:ms-docker-swarm,代码行数:25,代码来源:upid_test.go
示例14: TestConstrainteFilter
func TestConstrainteFilter(t *testing.T) {
var (
f = ConstraintFilter{}
nodes = testFixtures()
result []*node.Node
err error
)
// Without constraints we should get the unfiltered list of nodes back.
result, err = f.Filter(&cluster.ContainerConfig{}, nodes, true)
assert.NoError(t, err)
assert.Equal(t, result, nodes)
// Set a constraint that cannot be fulfilled and expect an error back.
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:does_not_exist==true"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.Error(t, err)
// Set a contraint that can only be filled by a single node.
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:name==node1"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.Equal(t, result[0], nodes[1])
// This constraint can only be fulfilled by a subset of nodes.
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:group==1"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 2)
assert.NotContains(t, result, nodes[2])
// Validate node pinning by id.
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==node-2-id"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.Equal(t, result[0], nodes[2])
// Validate node pinning by name.
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:node==node-1-name"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.Equal(t, result[0], nodes[1])
// Make sure constraints are evaluated as logical ANDs.
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:name==node0", "constraint:group==1"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.Equal(t, result[0], nodes[0])
// Check matching
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:region==us"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.Error(t, err)
assert.Len(t, result, 0)
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:region==us*"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 2)
result, err = f.Filter(cluster.BuildContainerConfig(containertypes.Config{Env: []string{"constraint:region==*us*"}}, containertypes.HostConfig{}, networktypes.NetworkingConfig{}), nodes, true)
assert.NoError(t, err)
assert.Len(t, result, 2)
}
开发者ID:swarm-hooks,项目名称:swarm,代码行数:60,代码来源:constraint_test.go
示例15: TestFragmentationSlowReader
func TestFragmentationSlowReader(t *testing.T) {
startReading, handlerComplete := make(chan struct{}), make(chan struct{})
handler := func(ctx context.Context, call *InboundCall) {
<-ctx.Done()
<-startReading
_, err := raw.ReadArgs(call)
assert.Error(t, err, "ReadArgs should fail since frames will be dropped due to slow reading")
close(handlerComplete)
}
// Inbound forward will timeout and cause a warning log.
opts := testutils.NewOpts().AddLogFilter("Unable to forward frame", 1)
WithVerifiedServer(t, opts, func(ch *Channel, hostPort string) {
ch.Register(HandlerFunc(handler), "echo")
arg2 := testutils.RandBytes(MaxFramePayloadSize * MexChannelBufferSize)
arg3 := testutils.RandBytes(MaxFramePayloadSize * (MexChannelBufferSize + 1))
ctx, cancel := NewContext(testutils.Timeout(15 * time.Millisecond))
defer cancel()
_, _, _, err := raw.Call(ctx, ch, hostPort, testServiceName, "echo", arg2, arg3)
assert.Error(t, err, "Call should timeout due to slow reader")
close(startReading)
<-handlerComplete
})
goroutines.VerifyNoLeaks(t, nil)
}
开发者ID:gl-works,项目名称:ringpop-go,代码行数:29,代码来源:connection_test.go
示例16: TestDockerForNamedImage
func TestDockerForNamedImage(t *testing.T) {
var c mocks.Client
defer c.AssertExpectations(t)
e := executor{client: &c}
ac, _ := e.getAuthConfig("test")
c.On("PullImage", docker.PullImageOptions{Repository: "test:latest"}, ac).
Return(os.ErrNotExist).
Once()
c.On("PullImage", docker.PullImageOptions{Repository: "tagged:tag"}, ac).
Return(os.ErrNotExist).
Once()
c.On("PullImage", docker.PullImageOptions{Repository: "[email protected]"}, ac).
Return(os.ErrNotExist).
Once()
image, err := e.pullDockerImage("test")
assert.Error(t, err)
assert.Nil(t, image)
image, err = e.pullDockerImage("tagged:tag")
assert.Error(t, err)
assert.Nil(t, image)
image, err = e.pullDockerImage("[email protected]")
assert.Error(t, err)
assert.Nil(t, image)
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:31,代码来源:executor_docker_test.go
示例17: TestFlag
func TestFlag(t *testing.T) {
Open("memstore", "")
defer Close()
// Get non existing flag
f, err := GetFlagValue("test")
assert.Nil(t, err, "GetFlagValue should have worked")
assert.Empty(t, "", f, "Getting a non-existing flag should return an empty string")
// Try to insert invalid flags
assert.Error(t, UpdateFlag("test", ""), "It should not accept a flag with an empty name or value")
assert.Error(t, UpdateFlag("", "test"), "It should not accept a flag with an empty name or value")
assert.Error(t, UpdateFlag("", ""), "It should not accept a flag with an empty name or value")
// Insert a flag and verify its value
assert.Nil(t, UpdateFlag("test", "test1"))
f, err = GetFlagValue("test")
assert.Nil(t, err, "GetFlagValue should have worked")
assert.Equal(t, "test1", f, "GetFlagValue did not return the expected value")
// Update a flag and verify its value
assert.Nil(t, UpdateFlag("test", "test2"))
f, err = GetFlagValue("test")
assert.Nil(t, err, "GetFlagValue should have worked")
assert.Equal(t, "test2", f, "GetFlagValue did not return the expected value")
}
开发者ID:kinvolk,项目名称:clair,代码行数:26,代码来源:flag_test.go
示例18: TestPasswords
func TestPasswords(t *testing.T) {
// Add password and ensure it gets reset
defer resetPassword(redisHost, password, "")
err := addPassword(redisHost, password)
if err != nil {
t.Fatal("adding password", err)
}
// Test Fetch metrics with missing password
f := mbtest.NewEventFetcher(t, getConfig(""))
_, err = f.Fetch()
if assert.Error(t, err, "missing password") {
assert.Contains(t, err, "NOAUTH Authentication required.")
}
// Config redis and metricset with an invalid password
f = mbtest.NewEventFetcher(t, getConfig("blah"))
_, err = f.Fetch()
if assert.Error(t, err, "invalid password") {
assert.Contains(t, err, "ERR invalid password")
}
// Config redis and metricset with a valid password
f = mbtest.NewEventFetcher(t, getConfig(password))
_, err = f.Fetch()
assert.NoError(t, err, "valid password")
}
开发者ID:ChongFeng,项目名称:beats,代码行数:27,代码来源:info_integration_test.go
示例19: TestDecompressFileToDir
func TestDecompressFileToDir(t *testing.T) {
fs, cmdRunner := getCompressorDependencies()
dc := NewTarballCompressor(cmdRunner, fs)
dstDir := createdTmpDir(t, fs)
defer os.RemoveAll(dstDir)
err := dc.DecompressFileToDir(fixtureSrcTgz(t), dstDir)
assert.NoError(t, err)
// regular files
content, err := fs.ReadFile(dstDir + "/not-nested-file")
assert.NoError(t, err)
assert.Contains(t, content, "not-nested-file")
// nested directory with a file
content, err = fs.ReadFile(dstDir + "/dir/nested-file")
assert.NoError(t, err)
assert.Contains(t, content, "nested-file")
// nested directory with a file inside another directory
content, err = fs.ReadFile(dstDir + "/dir/nested-dir/double-nested-file")
assert.NoError(t, err)
assert.Contains(t, content, "double-nested-file")
// directory without a file (empty)
content, err = fs.ReadFile(dstDir + "/empty-dir")
assert.Error(t, err)
assert.Contains(t, err.Error(), "is a directory")
// nested directory without a file (empty) inside another directory
content, err = fs.ReadFile(dstDir + "/dir/empty-nested-dir")
assert.Error(t, err)
assert.Contains(t, err.Error(), "is a directory")
}
开发者ID:ian-plosker,项目名称:bosh,代码行数:35,代码来源:tarball_compressor_test.go
示例20: TestParseBool
func TestParseBool(t *testing.T) {
tests := []struct {
in string
out bool
err bool
}{
{"yes", true, false},
{"true", true, false},
{"1", true, false},
{"no", false, false},
{"false", false, false},
{"0", false, false},
{"abc", false, true},
{"123", false, true},
{"123.4", false, true},
{"$123.4", false, true},
}
for _, tt := range tests {
parser := NewBooleanParser()
b, err := ParseBool(tt.in)
b2, err2 := parser.ParseBool(tt.in)
assert.Equal(t, tt.out, b)
assert.Equal(t, tt.out, b2)
if !tt.err {
assert.NoError(t, err)
assert.NoError(t, err2)
} else {
assert.Error(t, err)
assert.Error(t, err2)
}
}
}
开发者ID:shawnohare,项目名称:go-multiparse,代码行数:34,代码来源:bool_test.go
注:本文中的github.com/stretchr/testify/assert.Error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论