本文整理汇总了Golang中github.com/stretchr/testify/assert.NoError函数的典型用法代码示例。如果您正苦于以下问题:Golang NoError函数的具体用法?Golang NoError怎么用?Golang NoError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NoError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSessionLogin
// Test SessionLogin
func TestSessionLogin(t *testing.T) {
var (
c *ICSPClient
)
if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
_, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
data, err := c.SessionLogin()
// fmt.Printf("after SessionLogin: %s -> (err) %+v", data.ID, err)
assert.NoError(t, err, "SessionLogin threw error -> %s", err)
assert.NotEmpty(t, data.ID, fmt.Sprintf("SessionLogin is empty! something went wrong, err -> %s, data -> %+v\n", err, data))
assert.Equal(t, "none", c.APIKey)
c.APIKey = data.ID
err = c.SessionLogout()
assert.NoError(t, err, "SessionLogout threw error -> %s", err)
data, err = c.SessionLogin()
assert.NoError(t, err, "SessionLogin threw error -> %s", err)
} else {
_, c = getTestDriverU()
data, err := c.SessionLogin()
assert.Error(t, err, fmt.Sprintf("ALL ok, no error, caught as expected: %s,%+v\n", err, data))
assert.Equal(t, "none", c.APIKey)
}
}
示例2: TestTypeResolver_AdditionalItems
func TestTypeResolver_AdditionalItems(t *testing.T) {
_, resolver, err := basicTaskListResolver(t)
tpe := spec.StringProperty()
if assert.NoError(t, err) {
// arrays of primitives and string formats with additional formats
for _, val := range schTypeVals {
var sch spec.Schema
sch.Typed(val.Type, val.Format)
var coll spec.Schema
coll.Type = []string{"array"}
coll.Items = new(spec.SchemaOrArray)
coll.Items.Schema = tpe
coll.AdditionalItems = new(spec.SchemaOrBool)
coll.AdditionalItems.Schema = &sch
rt, err := resolver.ResolveSchema(&coll, true)
if assert.NoError(t, err) && assert.True(t, rt.IsArray) {
assert.True(t, rt.HasAdditionalItems)
assert.False(t, rt.IsNullable)
//if assert.NotNil(t, rt.ElementType) {
//assertPrimitiveResolve(t, "string", "", "string", *rt.ElementType)
//}
}
}
}
}
示例3: testAtomicPut
func testAtomicPut(t *testing.T, kv store.Store) {
key := "testAtomicPut"
value := []byte("world")
// Put the key
err := kv.Put(key, value, nil)
assert.NoError(t, err)
// Get should return the value and an incremented index
pair, err := kv.Get(key)
assert.NoError(t, err)
if assert.NotNil(t, pair) {
assert.NotNil(t, pair.Value)
}
assert.Equal(t, pair.Value, value)
assert.NotEqual(t, pair.LastIndex, 0)
// This CAS should fail: previous exists.
success, _, err := kv.AtomicPut(key, []byte("WORLD"), nil, nil)
assert.Error(t, err)
assert.False(t, success)
// This CAS should succeed
success, _, err = kv.AtomicPut(key, []byte("WORLD"), pair, nil)
assert.NoError(t, err)
assert.True(t, success)
// This CAS should fail, key exists.
pair.LastIndex = 6744
success, _, err = kv.AtomicPut(key, []byte("WORLDWORLD"), pair, nil)
assert.Error(t, err)
assert.False(t, success)
}
示例4: TestCollect
func TestCollect(t *testing.T) {
cm := &collectorManager{}
firstTime := time.Now().Add(-time.Hour)
secondTime := time.Now().Add(time.Hour)
f1 := &fakeCollector{
nextCollectionTime: firstTime,
}
f2 := &fakeCollector{
nextCollectionTime: secondTime,
}
assert := assert.New(t)
assert.NoError(cm.RegisterCollector(f1))
assert.NoError(cm.RegisterCollector(f2))
// First collection, everyone gets collected from.
nextTime, _, err := cm.Collect()
assert.Equal(firstTime, nextTime)
assert.NoError(err)
assert.Equal(1, f1.collectedFrom)
assert.Equal(1, f2.collectedFrom)
f1.nextCollectionTime = time.Now().Add(2 * time.Hour)
// Second collection, only the one that is ready gets collected from.
nextTime, _, err = cm.Collect()
assert.Equal(secondTime, nextTime)
assert.NoError(err)
assert.Equal(2, f1.collectedFrom)
assert.Equal(1, f2.collectedFrom)
}
示例5: TestDNSProvider_Present
func TestDNSProvider_Present(t *testing.T) {
os.Setenv("LINODE_API_KEY", "testing")
defer restoreEnv()
p, err := NewDNSProvider()
assert.NoError(t, err)
domain := "example.com"
keyAuth := "dGVzdGluZw=="
mockResponses := MockResponseMap{
"domain.list": MockResponse{
Response: []dns.Domain{
dns.Domain{
Domain: domain,
DomainID: 1234,
},
},
},
"domain.resource.create": MockResponse{
Response: dns.ResourceResponse{
ResourceID: 1234,
},
},
}
mockSrv := newMockServer(t, mockResponses)
defer mockSrv.Close()
p.linode.ToLinode().SetEndpoint(mockSrv.URL)
err = p.Present(domain, "", keyAuth)
assert.NoError(t, err)
}
示例6: TestResurrectStmtSqlMockNoTicker
func TestResurrectStmtSqlMockNoTicker(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()
mock.ExpectPrepare("INSERT INTO `xtable` \\(`path`,`value`\\) VALUES .+").
ExpectExec().WithArgs("gopher", 3141).WillReturnResult(sqlmock.NewResult(1, 1))
tw := newTypeWriterMocked(db)
assert.NoError(t, tw.Save("gopher", 3141))
assert.False(t, tw.Write.IsIdle())
assert.NoError(t, tw.Write.StopIdleChecker())
mock.ExpectPrepare("INSERT INTO `xtable` \\(`path`,`value`\\) VALUES .+").
ExpectExec().WithArgs("gopher", 3144).WillReturnResult(sqlmock.NewResult(1, 1))
assert.NoError(t, tw.Save("gopher", 3144))
// we make sure that all expectations were met
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("there were unfulfilled expections: %s", err)
}
}
示例7: Test_Transport_FetchSpec
func Test_Transport_FetchSpec(t *testing.T) {
// t.Skip()
root := "Spec"
halt, tree, ml, _, tr := seed(t, root)
defer halt()
mx, err := ml.FeedManifests(true, true, true, lists.NewFileList().ListDir(tree.CWD)...)
assert.NoError(t, err)
err = tr.Upload(mx)
assert.NoError(t, err)
// make spec
nameMap := map[string]proto.ID{}
for name, m := range mx {
nameMap[name] = m.ID
}
spec1, err := proto.NewSpec(time.Now().UnixNano(), nameMap, []string{})
assert.NoError(t, err)
err = tr.UploadSpec(spec1)
assert.NoError(t, err)
spec2, err := tr.GetSpec(spec1.ID)
assert.NoError(t, err)
assert.Equal(t, spec1.ID, spec2.ID)
}
示例8: TestEnum_ComputeInstance
func TestEnum_ComputeInstance(t *testing.T) {
// ensure that the enum validation for the anonymous object under the delegate property
// is rendered.
specDoc, err := spec.Load("../fixtures/codegen/todolist.enums.yml")
if assert.NoError(t, err) {
definitions := specDoc.Spec().Definitions
k := "ComputeInstance"
schema := definitions[k]
genModel, err := makeGenDefinition(k, "models", schema, specDoc)
if assert.NoError(t, err) {
buf := bytes.NewBuffer(nil)
err := modelTemplate.Execute(buf, genModel)
if assert.NoError(t, err) {
ff, err := formatGoFile("object_thing.go", buf.Bytes())
if assert.NoError(t, err) {
res := string(ff)
fmt.Println(res)
assertInCode(t, "Region string `json:\"region,omitempty\"`", res)
assertInCode(t, "var computeInstanceRegionEnum []interface{}", res)
assertInCode(t, "m.validateRegionEnum(\"region\", \"body\", m.Region)", res)
}
}
}
}
}
示例9: TestEnum_NewPrototype
func TestEnum_NewPrototype(t *testing.T) {
// ensure that the enum validation for the anonymous object under the delegate property
// is rendered.
specDoc, err := spec.Load("../fixtures/codegen/todolist.enums.yml")
if assert.NoError(t, err) {
definitions := specDoc.Spec().Definitions
k := "NewPrototype"
schema := definitions[k]
genModel, err := makeGenDefinition(k, "models", schema, specDoc)
if assert.NoError(t, err) {
buf := bytes.NewBuffer(nil)
err := modelTemplate.Execute(buf, genModel)
if assert.NoError(t, err) {
ff, err := formatGoFile("object_thing.go", buf.Bytes())
if assert.NoError(t, err) {
res := string(ff)
assertInCode(t, "ActivatingUser NewPrototypeActivatingUser `json:\"activating_user,omitempty\"`", res)
assertInCode(t, "Delegate NewPrototypeDelegate `json:\"delegate\"`", res)
assertInCode(t, "Role string `json:\"role\"`", res)
assertInCode(t, "var newPrototypeRoleEnum []interface{}", res)
assertInCode(t, "var newPrototypeDelegateKindEnum []interface{}", res)
assertInCode(t, "m.validateDelegate(formats)", res)
assertInCode(t, "m.validateRole(formats)", res)
assertInCode(t, "m.validateActivatingUser(formats)", res)
assertInCode(t, "m.Delegate.Validate(formats)", res)
assertInCode(t, "m.ActivatingUser.Validate(formats)", res)
}
}
}
}
}
示例10: TestEnum_SliceAndAdditionalItemsThing
func TestEnum_SliceAndAdditionalItemsThing(t *testing.T) {
specDoc, err := spec.Load("../fixtures/codegen/todolist.enums.yml")
if assert.NoError(t, err) {
definitions := specDoc.Spec().Definitions
k := "SliceAndAdditionalItemsThing"
schema := definitions[k]
genModel, err := makeGenDefinition(k, "models", schema, specDoc)
if assert.NoError(t, err) {
buf := bytes.NewBuffer(nil)
err := modelTemplate.Execute(buf, genModel)
if assert.NoError(t, err) {
ff, err := formatGoFile("slice_and_additional_items_thing.go", buf.Bytes())
if assert.NoError(t, err) {
res := string(ff)
assertInCode(t, "var sliceAndAdditionalItemsThingEnum []interface{}", res)
assertInCode(t, k+") validateSliceAndAdditionalItemsThingEnum(path, location string, value SliceAndAdditionalItemsThing)", res)
//assertInCode(t, "m.validateSliceAndAdditionalItemsThingEnum(\"\", \"body\", m)", res)
assertInCode(t, "var sliceAndAdditionalItemsThingP0Enum []interface{}", res)
assertInCode(t, k+") validateP0Enum(path, location string, value string)", res)
assertInCode(t, "m.validateP0Enum(\"0\", \"body\", m.P0)", res)
assertInCode(t, "var sliceAndAdditionalItemsThingItemsEnum []interface{}", res)
assertInCode(t, k+") validateSliceAndAdditionalItemsThingItemsEnum(path, location string, value float32)", res)
assertInCode(t, "m.validateSliceAndAdditionalItemsThingItemsEnum(strconv.Itoa(i+1), \"body\", m.SliceAndAdditionalItemsThingItems[i])", res)
}
}
}
}
}
示例11: TestEnum_MapThing
func TestEnum_MapThing(t *testing.T) {
specDoc, err := spec.Load("../fixtures/codegen/todolist.enums.yml")
if assert.NoError(t, err) {
definitions := specDoc.Spec().Definitions
k := "MapThing"
schema := definitions[k]
genModel, err := makeGenDefinition(k, "models", schema, specDoc)
if assert.NoError(t, err) {
buf := bytes.NewBuffer(nil)
err := modelTemplate.Execute(buf, genModel)
if assert.NoError(t, err) {
ff, err := formatGoFile("map_thing.go", buf.Bytes())
if assert.NoError(t, err) {
res := string(ff)
assertInCode(t, "var mapThingEnum []interface{}", res)
assertInCode(t, k+") validateMapThingEnum(path, location string, value map[string]string)", res)
assertInCode(t, "m.validateMapThingEnum(\"\", \"body\", m)", res)
assertInCode(t, "var mapThingValueEnum []interface{}", res)
assertInCode(t, k+") validateMapThingValueEnum(path, location string, value string)", res)
assertInCode(t, "m.validateMapThingValueEnum(k, \"body\", m[k])", res)
}
}
}
}
}
示例12: addTarget
func addTarget(t *testing.T, repo *NotaryRepository, targetName, targetFile string) *Target {
target, err := NewTarget(targetName, targetFile)
assert.NoError(t, err, "error creating target")
err = repo.AddTarget(target)
assert.NoError(t, err, "error adding target")
return target
}
示例13: TestSessionExpiredKey
// Test for expired key and see if RefreshLogin can restore the key if we have a bad key
func TestSessionExpiredKey(t *testing.T) {
var (
c *ICSPClient
d *ICSPTest
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
d, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
err := c.RefreshLogin()
log.Debugf(" login key -> %s", c.APIKey)
assert.NoError(t, err, "RefreshLogin threw error -> %s", err)
// force key to timeout
err = c.SetIdleTimeout(800)
assert.NoError(t, err, "SetIdleTimeout threw error -> %s", err)
// 1 millisecond and we should be timeout with the current key
time.Sleep(1 * time.Millisecond)
// verify we are timed out
_, err = c.GetIdleTimeout()
assert.Error(t, err, "should be 404 not found -> %s ", err)
// verify that we can access something from icps with this client
// This should not fail because it uses RefreshLogin to get a new login session and avoid timeout
serialNumber := d.Tc.GetTestData(d.Env, "SerialNumber").(string)
s, err := c.GetServerBySerialNumber(serialNumber)
assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, server -> %+v", err, s)
}
}
示例14: TestSetIdleTimeout
// Set idle timeout
func TestSetIdleTimeout(t *testing.T) {
var (
c *ICSPClient
// d *ICSPTest
testtime int64
)
if os.Getenv("ONEVIEW_TEST_ACCEPTANCE") == "true" {
testtime = 25000
_, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
err := c.RefreshLogin()
log.Debugf(" login key -> %s", c.APIKey)
assert.NoError(t, err, "RefreshLogin threw error -> %s", err)
err = c.SetIdleTimeout(testtime)
assert.NoError(t, err, "SetIdleTimeout threw error -> %s", err)
timeout, err := c.GetIdleTimeout()
assert.NoError(t, err, "GetIdleTimeout threw error -> %s", err)
assert.Equal(t, testtime, timeout, "Should get timeout equal, %s", timeout)
log.Debugf(" idle timeout -> %d", timeout)
}
}
示例15: doTestPrefixScan
func doTestPrefixScan(t *testing.T, node Node) {
for i := 1; i < 3; i++ {
n := node.From(fmt.Sprintf("%d%02d", 2015, i))
err := n.Save(&SimpleUser{ID: i, Name: "John"})
assert.NoError(t, err)
}
for i := 1; i < 4; i++ {
n := node.From(fmt.Sprintf("%d%02d", 2016, i))
err := n.Save(&SimpleUser{ID: i, Name: "John"})
assert.NoError(t, err)
}
assert.Len(t, node.PrefixScan("2015"), 2)
assert.Len(t, node.PrefixScan("20"), 5)
buckets2016 := node.PrefixScan("2016")
assert.Len(t, buckets2016, 3)
count, err := buckets2016[1].Count(&SimpleUser{})
assert.NoError(t, err)
assert.Equal(t, 1, count)
assert.NoError(t, buckets2016[1].One("ID", 2, &SimpleUser{}))
}