本文整理匯總了Golang中github.com/facebookgo/ensure.NotNil函數的典型用法代碼示例。如果您正苦於以下問題:Golang NotNil函數的具體用法?Golang NotNil怎麽用?Golang NotNil使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NotNil函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CheckOpsReader
// Verify if the items being read are as expected.
func CheckOpsReader(t *testing.T, loader OpsReader) {
expectedOpsRead := 0
const startingTs = 1396456709420
for op := loader.Next(); op != nil; op = loader.Next() {
expectedOpsRead += 1
ensure.NotNil(t, op)
ensure.DeepEqual(t, loader.OpsRead(), expectedOpsRead)
// check the "ts" field
CheckTime(t, float64(startingTs+loader.OpsRead()), op.Timestamp)
// check the insert doc
// certain key exists
for i := 1; i <= 5; i++ {
logTypeKey := fmt.Sprintf("logType%d", i)
logType, ok := GetElem(op.InsertDoc, logTypeKey)
if i != expectedOpsRead {
ensure.False(t, ok)
ensure.Nil(t, logType)
} else {
ensure.True(t, ok)
ensure.NotNil(t, logType)
}
}
// check the value for the shared key
message := fmt.Sprintf("m%d", expectedOpsRead)
actualMessage, ok := GetElem(op.InsertDoc, "message")
ensure.True(t, ok)
ensure.DeepEqual(t, actualMessage.(string), message)
}
ensure.DeepEqual(t, expectedOpsRead, 5)
}
示例2: TestUploadFiles
func TestUploadFiles(t *testing.T) {
t.Parallel()
h := parsecli.NewHarness(t)
defer h.Stop()
h.MakeEmptyRoot()
createRandomFiles(t, h)
names := []string{"a", "b"}
ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
switch filepath.Base(r.URL.Path) {
case names[0]:
ensure.NotNil(t, r.Header)
ensure.DeepEqual(t, r.Header.Get("Key"), "Value")
ensure.DeepEqual(t, r.Header.Get("Content-Type"), "application/octet-stream")
ensure.DeepEqual(t, r.Header.Get("Content-MD5"), "4JnleFGzGppuArF6N50EWg==")
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(`{"status":"success"}`)),
}, nil
case names[1]:
ensure.NotNil(t, r.Header)
ensure.DeepEqual(t, r.Header.Get("Key"), "Value")
ensure.DeepEqual(t, r.Header.Get("Content-Type"), "application/octet-stream")
ensure.DeepEqual(t, r.Header.Get("Content-MD5"), "Fv43qsp6mnGCJlC00VkOcA==")
return &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(strings.NewReader(`{"status":"success"}`)),
}, nil
default:
return &http.Response{
StatusCode: http.StatusInternalServerError,
Body: ioutil.NopCloser(strings.NewReader(`{"error":"something is wrong"}`)),
}, nil
}
})
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
var filenames []string
for _, name := range names {
filenames = append(filenames, filepath.Join(h.Env.Root, name))
}
ensure.Nil(t, uploadSymbolFiles(filenames[:],
map[string]string{"Key": "Value"}, true, h.Env))
for _, filename := range filenames {
_, err := os.Lstat(filename)
ensure.NotNil(t, err)
ensure.True(t, os.IsNotExist(err))
}
}
示例3: TestServerAbort
func TestServerAbort(t *testing.T) {
t.Parallel()
for _, code := range []int{200, 500} {
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Length", "4000")
w.WriteHeader(code)
w.Write(bytes.Repeat([]byte("a"), 3000))
},
),
)
u, err := url.Parse(server.URL)
ensure.Nil(t, err)
c := &parse.Client{
Credentials: defaultRestAPIKey,
BaseURL: u,
}
res := make(map[string]interface{})
_, err = c.Get(nil, res)
ensure.NotNil(t, err)
server.CloseClientConnections()
server.Close()
}
}
示例4: TestProvideWithFields
func TestProvideWithFields(t *testing.T) {
var g inject.Graph
a := &TypeAnswerStruct{}
err := g.Provide(&inject.Object{Value: a, Fields: map[string]*inject.Object{}})
ensure.NotNil(t, err)
ensure.DeepEqual(t, err.Error(), "fields were specified on object *inject_test.TypeAnswerStruct when it was provided")
}
示例5: TestServerAbort
func TestServerAbort(t *testing.T) {
t.Parallel()
for _, code := range []int{200, 500} {
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Length", "4000")
w.WriteHeader(code)
w.Write(bytes.Repeat([]byte("a"), 3000))
},
),
)
u, err := url.Parse(server.URL)
ensure.Nil(t, err)
c := &fbapi.Client{
BaseURL: u,
}
_, err = c.Do(&http.Request{Method: "GET"}, nil)
ensure.NotNil(t, err)
ensure.Err(t, err, regexp.MustCompile("(invalid character|EOF)"))
server.CloseClientConnections()
server.Close()
}
}
示例6: TestPrintListNoConfig
func TestPrintListNoConfig(t *testing.T) {
t.Parallel()
h, l := newListCmdHarness(t)
h.makeEmptyRoot()
defer h.Stop()
ensure.NotNil(t, l.printListOfApps(h.env))
ensure.DeepEqual(t, h.Out.String(), "")
}
示例7: TestMissingCredentials
func TestMissingCredentials(t *testing.T) {
t.Parallel()
var c parse.Client
req := http.Request{Method: "GET", URL: &url.URL{Path: "classes/Foo/Bar"}}
_, err := c.Do(&req, nil, nil)
ensure.NotNil(t, err)
ensure.Err(t, err, regexp.MustCompile(`parse: api error with message="unauthorized"`))
}
示例8: TestInheritErrorOnListenUnixWithInvalidCount
func TestInheritErrorOnListenUnixWithInvalidCount(t *testing.T) {
var n Net
os.Setenv(envCountKey, "a")
tmpdir, err := ioutil.TempDir("", "TestInheritErrorOnListenUnixWithInvalidCount-")
ensure.Nil(t, err)
ensure.Nil(t, os.RemoveAll(tmpdir))
_, err = n.Listen("unix", filepath.Join(tmpdir, "socket"))
ensure.NotNil(t, err)
}
示例9: TestBase64MD5OfFileNoFile
func TestBase64MD5OfFileNoFile(t *testing.T) {
t.Parallel()
h := parsecli.NewHarness(t)
defer h.Stop()
h.MakeEmptyRoot()
testFile := filepath.Join(h.Env.Root, "test")
_, err := base64MD5OfFile(testFile)
ensure.NotNil(t, err)
}
示例10: TestReleasesCmdError
func TestReleasesCmdError(t *testing.T) {
h, c := newReleasesCmdHarness(t)
defer h.Stop()
ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
return nil, stackerr.New("Throws error")
})
h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
ensure.NotNil(t, c.run(h.Env, &parsecli.Context{}))
}
示例11: TestNewConfig
func TestNewConfig(t *testing.T) {
var err error
// CASE 1: unmarshalling err
_, err = newConfig(strings.NewReader("?????"))
ensure.NotNil(t, err)
// CASE 2: success!
_, err = newConfig(strings.NewReader(""))
ensure.Nil(t, err)
}
示例12: Start
// Start starts server used for MockS3
func (s *MockS3) Start(t *testing.T) {
srv, err := s3test.NewServer(s.config)
ensure.Nil(t, err)
ensure.NotNil(t, srv)
s.srv = srv
s.region = aws.Region{
Name: "faux-region-1",
S3Endpoint: srv.URL(),
S3LocationConstraint: true, // s3test server requires a LocationConstraint
}
}
示例13: CheckSetStartTime
func CheckSetStartTime(t *testing.T, loader OpsReader) {
expectedOpsRead := 0
numSkipped, err := loader.SetStartTime(1396456709424)
ensure.Nil(t, err)
ensure.DeepEqual(t, numSkipped, int64(4))
for op := loader.Next(); op != nil; op = loader.Next() {
expectedOpsRead += 1
ensure.NotNil(t, op)
ensure.DeepEqual(t, loader.OpsRead(), expectedOpsRead)
}
// Verify that only 4 ops are read, since we skipped one
ensure.DeepEqual(t, expectedOpsRead, 1)
}
示例14: CheckSkipOps
func CheckSkipOps(t *testing.T, loader OpsReader) {
expectedOpsRead := 0
// Skip a single op
loader.SkipOps(1)
// Read all remaining ops
for op := loader.Next(); op != nil; op = loader.Next() {
expectedOpsRead += 1
ensure.NotNil(t, op)
ensure.DeepEqual(t, loader.OpsRead(), expectedOpsRead)
}
// Verify that only 4 ops are read, since we skipped one
ensure.DeepEqual(t, expectedOpsRead, 4)
}
示例15: TestSafeGetInt
func TestSafeGetInt(t *testing.T) {
val, err := safeGetInt(int32(11))
ensure.Nil(t, err)
ensure.DeepEqual(t, val, int(11))
val, err = safeGetInt(int64(11))
ensure.Nil(t, err)
ensure.DeepEqual(t, val, int(11))
val, err = safeGetInt(float32(11))
ensure.Nil(t, err)
ensure.DeepEqual(t, val, int(11))
val, err = safeGetInt(float64(11))
ensure.Nil(t, err)
ensure.DeepEqual(t, val, int(11))
val, err = safeGetInt("a")
ensure.NotNil(t, err)
}