Documentation ¶
Index ¶
- Variables
- func CSVColumnParser(s string) []byte
- func FromCSVString(columns []*sqlmock.Column, rows *sqlmock.Rows, s string) *sqlmock.Rows
- func NewRequestFromFile(c client.Client, reqfile string) (client.Request, error)
- func NewResponseFromFile(rspfile string) (*codec.Frame, error)
- func Run(ctx context.Context, c client.Client, m sqlmock.Sqlmock, dir string, ...) error
- func SQLFromBytes(m sqlmock.Sqlmock, buf []byte) error
- func SQLFromFile(m sqlmock.Sqlmock, name string) error
- func SQLFromReader(m sqlmock.Sqlmock, r io.Reader) error
- func SQLFromString(m sqlmock.Sqlmock, buf string) error
- type Case
- type Extension
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ExtToTypes map file extension to content type ExtToTypes = map[string][]string{ "json": {"application/json", "application/grpc+json"}, "yaml": {"application/yaml", "application/yml", "text/yaml", "text/yml"}, "yml": {"application/yaml", "application/yml", "text/yaml", "text/yml"}, "proto": {"application/grpc", "application/grpc+proto", "application/proto"}, } // DefaultExts specifies default file extensions to load data DefaultExts = []string{"csv", "json", "yaml", "yml", "proto"} // Codecs map to detect codec for test file or request content type Codecs map[string]codec.Codec // ResponseCompareFunc used to compare actual response with test case data ResponseCompareFunc = func(expectRsp []byte, testRsp interface{}, expectCodec codec.Codec, testCodec codec.Codec) error { var err error expectMap := make(map[string]interface{}) if err = expectCodec.Unmarshal(expectRsp, &expectMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } testMap := make(map[string]interface{}) switch v := testRsp.(type) { case *codec.Frame: if err = testCodec.Unmarshal(v.Data, &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } case *errors.Error: if err = expectCodec.Unmarshal([]byte(v.Error()), &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } case error: st, ok := status.FromError(v) if !ok { return v } me := errors.Parse(st.Message()) if me.Code != 0 { if err = expectCodec.Unmarshal([]byte(me.Error()), &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } break } for _, se := range st.Details() { switch ne := se.(type) { case proto.Message: buf, err := testCodec.Marshal(ne) if err != nil { return fmt.Errorf("failed to marshal err: %w", err) } if err = testCodec.Unmarshal(buf, &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } default: return st.Err() } } case interface{ GRPCStatus() *status.Status }: st := v.GRPCStatus() me := errors.Parse(st.Message()) if me.Code != 0 { if err = expectCodec.Unmarshal([]byte(me.Error()), &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } break } case *status.Status: me := errors.Parse(v.Message()) if me.Code != 0 { if err = expectCodec.Unmarshal([]byte(me.Error()), &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } break } for _, se := range v.Details() { switch ne := se.(type) { case proto.Message: buf, err := testCodec.Marshal(ne) if err != nil { return fmt.Errorf("failed to marshal err: %w", err) } if err = testCodec.Unmarshal(buf, &testMap); err != nil { return fmt.Errorf("failed to unmarshal err: %w", err) } default: return v.Err() } } } if !reflect.DeepEqual(expectMap, testMap) { return fmt.Errorf("test: %s != rsp: %s", expectMap, testMap) } return nil } )
View Source
var ErrUnknownContentType = fmt.Errorf("unknown content type")
Functions ¶
func CSVColumnParser ¶
func FromCSVString ¶
func NewRequestFromFile ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.