spec2

package
v0.0.0-...-1814096 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultWindowSize is the value of default connection window size.
	DefaultWindowSize = 65535
	// DefaultFrameSize is the value of default frame size.
	DefaultFrameSize = 16384
)
View Source
const (
	ExpectedConnectionClosed = "Connection closed"
	ExpectedStreamClosed     = "Stream closed"
	ExpectedGoAwayFrame      = "GOAWAY Frame (Error Code: %s)"
	ExpectedRSTStreamFrame   = "RST_STREAM Frame (Error Code: %s)"
)

Variables

View Source
var (
	DefaultLength  uint32        = math.MaxUint32
	DefaultFlags   http2.Flags   = math.MaxUint8
	DefaultErrCode http2.ErrCode = math.MaxUint8
)
View Source
var (
	// ErrTimeout is used when the test times out.
	ErrTimeout = errors.New("Timeout")
	// ErrSkipped is used when the test skipped.
	ErrSkipped = errors.New("Skipped")
)

Functions

func CommonHeaders

func CommonHeaders(c *config.Config) []hpack.HeaderField

CommonHeaders returns a array of header field of HPACK contained common http headers used in various test case.

func CommonRespHeaders

func CommonRespHeaders(c *config.Config) []hpack.HeaderField

CommonRespHeaders returns a array of header field of HPACK contained common http headers used in various test case.

func DummyBytes

func DummyBytes(len int) []byte

DummyBytes returns a array of byte with specified length.

func DummyHeaders

func DummyHeaders(c *config.Config, len int) []hpack.HeaderField

DummyHeaders returns a array of header field of HPACK contained dummy string values.

func DummyRespHeaders

func DummyRespHeaders(c *config.Config, len int) []hpack.HeaderField

func DummyString

func DummyString(len int) string

DummyString returns a dummy string with specified length.

func HeaderField

func HeaderField(name, value string) hpack.HeaderField

HeaderField returns a header field of HPACK with specified name and value.

func ServerDataLength

func ServerDataLength(c *config.Config) (int, error)

ServerDataLength returns the total length of the DATA frame of /.

func VerifyConnectionClose

func VerifyConnectionClose(conn *Conn) error

VerifyConnectionClose verifies whether the connection was closed.

func VerifyConnectionError

func VerifyConnectionError(conn *Conn, codes ...http2.ErrCode) error

VerifyConnectionError verifies whether a connection error of HTTP/2 has occurred.

func VerifyErrorCode

func VerifyErrorCode(codes []http2.ErrCode, code http2.ErrCode) bool

VerifyErrorCode verifies whether the specified error code is the expected error code.

func VerifyEventType

func VerifyEventType(conn *Conn, et EventType) error

VerifyEventType verifies whether a frame with specified type has received.

func VerifyHeadersFrame

func VerifyHeadersFrame(conn *Conn, streamID uint32) error

VerifyHeadersFrame verifies whether a HEADERS frame with specified stream ID has received.

func VerifyPingFrameOrConnectionClose

func VerifyPingFrameOrConnectionClose(conn *Conn, data [8]byte) error

VerifyPingFrameOrConnectionClose verifies whether a PING frame with ACK flag has received or the connection was closed.

func VerifyPingFrameWithAck

func VerifyPingFrameWithAck(conn *Conn, data [8]byte) error

VerifyPingFrameWithAck verifies whether a PING frame with ACK flag has received.

func VerifySettingsFrameWithAck

func VerifySettingsFrameWithAck(conn *Conn) error

VerifySettingsFrameWithAck verifies whether a SETTINGS frame with ACK flag has received.

func VerifyStreamClose

func VerifyStreamClose(conn *Conn) error

VerifyStreamClose verifies whether a stream close of HTTP/2 has occurred.

func VerifyStreamError

func VerifyStreamError(conn *Conn, codes ...http2.ErrCode) error

VerifyStreamError verifies whether a stream error of HTTP/2 has occurred.

Types

type ClientTestCase

type ClientTestCase struct {
	Seq         int
	Desc        string
	Requirement string
	Parent      *ClientTestGroup
	Result      *ClientTestResult
	Run         func(c *config.Config, conn *Conn) error

	Port int
	Done chan bool
}

ClientTestCase represents a test case.

func (*ClientTestCase) FullPath

func (tc *ClientTestCase) FullPath(c *config.Config) string

func (*ClientTestCase) Test

func (tc *ClientTestCase) Test(c *config.Config) error

Test runs itself as a test case.

type ClientTestGroup

type ClientTestGroup struct {
	Key     string
	Section string
	Name    string
	Parent  *ClientTestGroup
	Groups  []*ClientTestGroup
	Tests   []*ClientTestCase

	PassedCount  int
	FailedCount  int
	SkippedCount int
}

ClientTestGroup represents a group of test case.

func (*ClientTestGroup) AddTestCase

func (tg *ClientTestGroup) AddTestCase(tc *ClientTestCase)

AddTestCase registers a test to this group.

func (*ClientTestGroup) AddTestGroup

func (tg *ClientTestGroup) AddTestGroup(stg *ClientTestGroup)

AddTestGroup registers a group to this group.

func (*ClientTestGroup) ClientTestCases

func (tg *ClientTestGroup) ClientTestCases(testCases map[int]*ClientTestCase, c *config.Config, currentPort int) int

func (*ClientTestGroup) ID

func (tg *ClientTestGroup) ID() string

ID returns the unique ID of this group.

func (*ClientTestGroup) IncRecursive

func (tg *ClientTestGroup) IncRecursive(failed bool, skipped bool, inc int)

func (*ClientTestGroup) IsRoot

func (tg *ClientTestGroup) IsRoot() bool

IsRoot returns bool as to whether it is the parent of all groups.

func (*ClientTestGroup) Level

func (tg *ClientTestGroup) Level() int

Level returns a number. Level is determined by Key and the number of "." included in Section.

func (*ClientTestGroup) Test

func (tg *ClientTestGroup) Test(c *config.Config)

Test runs all the tests included in this group.

func (*ClientTestGroup) Title

func (tg *ClientTestGroup) Title() string

Title returns the title of this group.

type ClientTestResult

type ClientTestResult struct {
	ClientTestCase *ClientTestCase
	Error          error
	Duration       time.Duration

	Skipped bool
	Failed  bool
}

ClientTestResult represents a result of test case.

func NewClientTestResult

func NewClientTestResult(tc *ClientTestCase, err error, d time.Duration) *ClientTestResult

NewClientTestResult returns a ClientTestResult.

func (*ClientTestResult) Print

func (tr *ClientTestResult) Print()

Print prints the result of test case.

type Conn

type Conn struct {
	net.Conn

	Settings map[http2.SettingID]uint32
	Timeout  time.Duration
	Verbose  bool
	Closed   bool

	WindowUpdate bool
	WindowSize   map[uint32]int
	// contains filtered or unexported fields
}

Conn represent a HTTP/2 connection. This struct contains settings information, current window size, encoder of HPACK and frame encoder.

func Accept

func Accept(c *config.Config, baseConn net.Conn) (*Conn, error)

func Dial

func Dial(c *config.Config) (*Conn, error)

Dial connects to the server based on configuration.

func (*Conn) EncodeHeaders

func (conn *Conn) EncodeHeaders(headers []hpack.HeaderField) []byte

EncodeHeaders encodes header and returns encoded bytes. Conn retains encoding context and next call of EncodeHeaders will be performed using the same encoding context.

func (*Conn) Handshake

func (conn *Conn) Handshake() error

Handshake performs HTTP/2 handshake with the server.

func (*Conn) MaxFrameSize

func (conn *Conn) MaxFrameSize() int

MaxFrameSize returns value of Handshake performs HTTP/2 handshake with the server.

func (*Conn) ReadClientPreface

func (conn *Conn) ReadClientPreface() (string, error)

func (*Conn) ReadRequest

func (conn *Conn) ReadRequest() (*Request, error)

func (*Conn) Send

func (conn *Conn) Send(payload []byte) error

Send sends a byte sequense. This function is used to send a raw data in tests.

func (*Conn) SetMaxDynamicTableSize

func (conn *Conn) SetMaxDynamicTableSize(v uint32)

SetMaxDynamicTableSize changes the dynamic header table size to v.

func (*Conn) WaitEvent

func (conn *Conn) WaitEvent() Event

WaitEvent returns a event occured on connection. This function is used to wait the next event on the connection.

func (*Conn) WaitEventByType

func (conn *Conn) WaitEventByType(evt EventType) (Event, bool)

WaitEventByType returns a specified event occured on connection. This function is used to wait the next event that has specified type on the connection.

func (*Conn) WriteContinuation

func (conn *Conn) WriteContinuation(streamID uint32, endHeaders bool, headerBlockFragment []byte) error

WriteContinuation sends a CONTINUATION frame.

func (*Conn) WriteData

func (conn *Conn) WriteData(streamID uint32, endStream bool, data []byte) error

WriteData sends a DATA frame.

func (*Conn) WriteDataPadded

func (conn *Conn) WriteDataPadded(streamID uint32, endStream bool, data, pad []byte) error

WriteDataPadded sends a DATA frame with padding.

func (*Conn) WriteGoAway

func (conn *Conn) WriteGoAway(maxStreamID uint32, code http2.ErrCode, debugData []byte) error

WriteGoAway sends a GOAWAY frame.

func (*Conn) WriteHeaders

func (conn *Conn) WriteHeaders(p http2.HeadersFrameParam) error

WriteHeaders sends a HEADERS frame.

func (*Conn) WritePing

func (conn *Conn) WritePing(ack bool, data [8]byte) error

WritePing sends a PING frame.

func (*Conn) WritePriority

func (conn *Conn) WritePriority(streamID uint32, p http2.PriorityParam) error

WritePriority sends a PRIORITY frame.

func (*Conn) WritePushPromise

func (conn *Conn) WritePushPromise(p http2.PushPromiseParam) error

WritePushPromise sends a PUSH_PROMISE frame.

func (*Conn) WriteRSTStream

func (conn *Conn) WriteRSTStream(streamID uint32, code http2.ErrCode) error

WriteRSTStream sends a RST_STREAM frame.

func (*Conn) WriteRawFrame

func (conn *Conn) WriteRawFrame(t http2.FrameType, flags http2.Flags, streamID uint32, payload []byte) error

func (*Conn) WriteSettings

func (conn *Conn) WriteSettings(settings ...http2.Setting) error

WriteSettings sends a SETTINGS frame.

func (*Conn) WriteSettingsAck

func (conn *Conn) WriteSettingsAck() error

WriteSettingsAck sends a SETTINGS frame with ACK flag.

func (*Conn) WriteSuccessResponse

func (conn *Conn) WriteSuccessResponse(streamID uint32, c *config.Config)

func (*Conn) WriteWindowUpdate

func (conn *Conn) WriteWindowUpdate(streamID, incr uint32) error

WriteWindowUpdate sends a WINDOW_UPDATE frame.

type ConnectionClosedEvent

type ConnectionClosedEvent struct{}

func (ConnectionClosedEvent) String

func (ev ConnectionClosedEvent) String() string

func (ConnectionClosedEvent) Type

func (ev ConnectionClosedEvent) Type() EventType

type ContinuationFrameEvent

type ContinuationFrameEvent struct {
	http2.ContinuationFrame
}

func (ContinuationFrameEvent) String

func (ev ContinuationFrameEvent) String() string

func (ContinuationFrameEvent) Type

type DataFrameEvent

type DataFrameEvent struct {
	http2.DataFrame
}

func (DataFrameEvent) String

func (ev DataFrameEvent) String() string

func (DataFrameEvent) Type

func (ev DataFrameEvent) Type() EventType

type ErrorEvent

type ErrorEvent struct {
	Error error
}

func (ErrorEvent) String

func (ev ErrorEvent) String() string

func (ErrorEvent) Type

func (ev ErrorEvent) Type() EventType

type Event

type Event interface {
	Type() EventType
	String() string
}

type EventFrame

type EventFrame interface {
	String() string
	Header() http2.FrameHeader
}

type EventType

type EventType uint8
const (
	EventDataFrame         EventType = 0x0
	EventHeadersFrame      EventType = 0x1
	EventPriorityFrame     EventType = 0x2
	EventRSTStreamFrame    EventType = 0x3
	EventSettingsFrame     EventType = 0x4
	EventPushPromiseFrame  EventType = 0x5
	EventPingFrame         EventType = 0x6
	EventGoAwayFrame       EventType = 0x7
	EventWindowUpdateFrame EventType = 0x8
	EventContinuationFrame EventType = 0x9
	EventRawData           EventType = 0x10
	EventConnectionClosed  EventType = 0x11
	EventError             EventType = 0x12
	EventTimeout           EventType = 0x13
)

func (EventType) String

func (et EventType) String() string

type GoAwayFrameEvent

type GoAwayFrameEvent struct {
	http2.GoAwayFrame
}

func (GoAwayFrameEvent) String

func (ev GoAwayFrameEvent) String() string

func (GoAwayFrameEvent) Type

func (ev GoAwayFrameEvent) Type() EventType

type HeadersFrameEvent

type HeadersFrameEvent struct {
	http2.HeadersFrame
}

func (HeadersFrameEvent) String

func (ev HeadersFrameEvent) String() string

func (HeadersFrameEvent) Type

func (ev HeadersFrameEvent) Type() EventType

type PingFrameEvent

type PingFrameEvent struct {
	http2.PingFrame
}

func (PingFrameEvent) String

func (ev PingFrameEvent) String() string

func (PingFrameEvent) Type

func (ev PingFrameEvent) Type() EventType

type PriorityFrameEvent

type PriorityFrameEvent struct {
	http2.PriorityFrame
}

func (PriorityFrameEvent) String

func (ev PriorityFrameEvent) String() string

func (PriorityFrameEvent) Type

func (ev PriorityFrameEvent) Type() EventType

type PushPromiseFrameEvent

type PushPromiseFrameEvent struct {
	http2.PushPromiseFrame
}

func (PushPromiseFrameEvent) String

func (ev PushPromiseFrameEvent) String() string

func (PushPromiseFrameEvent) Type

func (ev PushPromiseFrameEvent) Type() EventType

type RSTStreamFrameEvent

type RSTStreamFrameEvent struct {
	http2.RSTStreamFrame
}

func (RSTStreamFrameEvent) String

func (ev RSTStreamFrameEvent) String() string

func (RSTStreamFrameEvent) Type

func (ev RSTStreamFrameEvent) Type() EventType

type RawDataEvent

type RawDataEvent struct {
	Payload []byte
}

func (RawDataEvent) String

func (ev RawDataEvent) String() string

func (RawDataEvent) Type

func (ev RawDataEvent) Type() EventType

type Request

type Request struct {
	StreamID uint32
	Headers  []hpack.HeaderField
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func Listen

func Listen(c *config.Config, tg *ClientTestGroup) (*Server, error)

func (*Server) Close

func (server *Server) Close()

func (*Server) RunListener

func (server *Server) RunListener(listener net.Listener, tc *ClientTestCase)

type SettingsFrameEvent

type SettingsFrameEvent struct {
	http2.SettingsFrame
}

func (SettingsFrameEvent) String

func (ev SettingsFrameEvent) String() string

func (SettingsFrameEvent) Type

func (ev SettingsFrameEvent) Type() EventType

type TestCase

type TestCase struct {
	Desc        string
	Requirement string
	Strict      bool
	Parent      *TestGroup
	Result      *TestResult
	Run         func(c *config.Config, conn *Conn) error
}

TestCase represents a test case.

func (*TestCase) Test

func (tc *TestCase) Test(c *config.Config, seq int) error

Test runs itself as a test case.

type TestError

type TestError struct {
	Expected []string
	Actual   string
}

TestError represents a error result of test case and implements type error.

func (TestError) Error

func (e TestError) Error() string

Error returns a string containing the reason of the error.

type TestGroup

type TestGroup struct {
	Key         string
	Section     string
	Name        string
	Strict      bool
	Parent      *TestGroup
	Groups      []*TestGroup
	Tests       []*TestCase
	StrictTests []*TestCase

	PassedCount  int
	FailedCount  int
	SkippedCount int
}

TestGroup represents a group of test case.

func (*TestGroup) AddTestCase

func (tg *TestGroup) AddTestCase(tc *TestCase)

AddTestCase registers a test to this group.

func (*TestGroup) AddTestGroup

func (tg *TestGroup) AddTestGroup(stg *TestGroup)

AddTestGroup registers a group to this group.

func (*TestGroup) ID

func (tg *TestGroup) ID() string

ID returns the unique ID of this group.

func (*TestGroup) IsRoot

func (tg *TestGroup) IsRoot() bool

IsRoot returns bool as to whether it is the parent of all groups.

func (*TestGroup) Level

func (tg *TestGroup) Level() int

Level returns a number. Level is determined by Key and the number of "." included in Section.

func (*TestGroup) Test

func (tg *TestGroup) Test(c *config.Config)

Test runs all the tests included in this group.

func (*TestGroup) Title

func (tg *TestGroup) Title() string

Title returns the title of this group.

type TestResult

type TestResult struct {
	TestCase   *TestCase
	Sequence   int
	Error      error
	Duration   time.Duration
	SourceAddr net.Addr

	Skipped bool
	Failed  bool
}

TestResult represents a result of test case.

func NewTestResult

func NewTestResult(tc *TestCase, seq int, err error, d time.Duration, addr net.Addr) *TestResult

NewTestResult returns a TestResult.

func (*TestResult) Print

func (tr *TestResult) Print()

Print prints the result of test case.

type TimeoutEvent

type TimeoutEvent struct{}

func (TimeoutEvent) String

func (ev TimeoutEvent) String() string

func (TimeoutEvent) Type

func (ev TimeoutEvent) Type() EventType

type WindowUpdateFrameEvent

type WindowUpdateFrameEvent struct {
	http2.WindowUpdateFrame
}

func (WindowUpdateFrameEvent) String

func (ev WindowUpdateFrameEvent) String() string

func (WindowUpdateFrameEvent) Type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL