// ExpectJsonType checks if the types of the response
// JSON and the supplied JSON match
//
// path can be a dot joined field names.
// ex:  'path.to.subobject.field'
558441
func (F *Frisby) ExpectJsonType(path string, val_type reflect.Kind) *Frisby {
	Global.NumAsserts++
	json, err := F.Resp.Json()
	if err != nil {
		F.AddError(err.Error())
		return F
	}

	if path != "" {
		path_items := strings.Split(path, Global.PathSeparator)
		json = json.GetPath(path_items...)
	}

	json_json := json.Interface()

	json_val := reflect.ValueOf(json_json)
	if val_type != json_val.Kind() {
		err_str := fmt.Sprintf("Expect Json %q type to be %q, but got %T", path, val_type, json_json)
		F.AddError(err_str)
	}

	return F
}
231769
func ErrorType(t testing.TB, expr interface{}, typ error, args ...interface{}) {
	if IsNil(expr) { // 空值，必定没有错误
		assert(t, false, args, []interface{}{"ErrorType 失败，实际值为 Nil：[%T]", expr})
		return
	}

	if _, ok := expr.(error); !ok {
		assert(t, false, args, []interface{}{"ErrorType 失败，实际类型为[%T]，且无法转换成 error 接口", expr})
		return
	}

	t1 := reflect.TypeOf(expr)
	t2 := reflect.TypeOf(typ)
	assert(t, t1 == t2, args, []interface{}{"ErrorType 失败，v1[%v]为一个错误类型，但与v2[%v]的类型不相同", t1, t2})
}
337257
func (wfe *WebFrontEndImpl) enforceJWSAuthType(
	jws *jose.JSONWebSignature,
	expectedAuthType jwsAuthType) *probs.ProblemDetails {
	// Check the auth type for the provided JWS
	authType, prob := checkJWSAuthType(jws)
	if prob != nil {
		wfe.stats.joseErrorCount.With(prometheus.Labels{"type": "JWSAuthTypeInvalid"}).Inc()
		return prob
	}
	// If the auth type isn't the one expected return a sensible problem based on
	// what was expected
	if authType != expectedAuthType {
		wfe.stats.joseErrorCount.With(prometheus.Labels{"type": "JWSAuthTypeWrong"}).Inc()
		switch expectedAuthType {
		case embeddedKeyID:
			return probs.Malformed("No Key ID in JWS header")
		case embeddedJWK:
			return probs.Malformed("No embedded JWK in JWS header")
		}
	}
	return nil
}
205833
func IsType(expected interface{}, actual interface{}) bool {
	return IsEqual(reflect.TypeOf(expected), reflect.TypeOf(actual))
}
272211
func (this *import_data_parser) expect_special(special string) {
	i := 0
	for i < len(special) {
		if this.toktype != rune(special[i]) {
			break
		}

		this.next()
		i++
	}

	if i < len(special) {
		this.errorf("expected: \"%s\", got something else", special)
	}
}
763832
func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	return IsType(t, expectedType, object, append([]interface{}{msg}, args...)...)
}
907606
func CheckForJSON(r *http.Request) error {
	ct := r.Header.Get("Content-Type")

	// No Content-Type header is ok as long as there's no Body
	if ct == "" {
		if r.Body == nil || r.ContentLength == 0 {
			return nil
		}
	}

	// Otherwise it better be json
	if matchesContentType(ct, "application/json") {
		return nil
	}
	return errdefs.InvalidParameter(errors.Errorf("Content-Type specified (%s) must be 'application/json'", ct))
}
774864
func (c *Cmd) ExpectMap(response map[string]string) *Cmd {
	var values []interface{}
	for key, value := range response {
		values = append(values, []byte(key))
		values = append(values, []byte(value))
	}
	c.Responses = append(c.Responses, Response{values, nil})
	return c
}
142567
func reflectTypeToJSONType(xT descLookupFunc, rt reflect.Type) string {
	kind := rt.Kind()
	if isNumeric(kind) {
		return xT("json-type-numeric")
	}

	switch kind {
	case reflect.String:
		return xT("json-type-string")

	case reflect.Bool:
		return xT("json-type-bool")

	case reflect.Array, reflect.Slice:
		return xT("json-type-array") + reflectTypeToJSONType(xT,
			rt.Elem())

	case reflect.Struct:
		return xT("json-type-object")

	case reflect.Map:
		return xT("json-type-object")
	}

	return xT("json-type-value")
}
4042
func (t *T) ExpectErrorf(err error, spec string, args ...interface{}) {
	if err != nil {
		return
	}
	prefix := fmt.Sprintf(spec, args...) + ": "
	t.Fatalf("%sError not returned when one was expected.", prefix)
}
329729
func (s Slice) AssertType(t ValueType) error {
	if found := typeMap[s.head()]; found != t {
		return WithStack(InvalidTypeError{Message: fmt.Sprintf("expected type '%s', got '%s'", t, found)})
	}
	return nil
}
431670
func IsBuilderUnexpectedType(err error) bool {
	_, ok := Cause(err).(BuilderUnexpectedTypeError)
	return ok
}
1290819
func (err BadParameterError) Expected(expected interface{}) BadParameterError {
	err.expectedValue = expected
	err.hasExpectedValue = true
	return err
}
606369
func (c *Config) PathForType(rt reflect.Type) (*path.Path, error) {
	l := c.newLoader(nil)
	return l.makePathForType(rt, "", false)
}
710175
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
	if h, ok := a.t.(tHelper); ok {
		h.Helper()
	}
	return IsType(a.t, expectedType, object, msgAndArgs...)
}
1180603
func matchesContentType(contentType, expectedType string) bool {
	mimetype, _, err := mime.ParseMediaType(contentType)
	if err != nil {
		logrus.Errorf("Error parsing media type: %s error: %v", contentType, err)
	}
	return err == nil && mimetype == expectedType
}
17711
func findFieldOfType(reply reflect.Type, fieldName string) (reflect.StructField, bool) {
	for reply.Kind() == reflect.Ptr {
		reply = reply.Elem()
	}
	if reply.Kind() == reflect.Struct {
		field, found := reply.FieldByName(fieldName)
		return field, found
	}
	return reflect.StructField{}, false
}