diff options
author | clsr <clsr@clsr.net> | 2017-09-04 13:15:32 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-09-04 13:15:32 +0200 |
commit | 4171437282e4f57c8d14a1459554622a01861f9c (patch) | |
tree | 0cfe6a11089979e65ed3694c65f8038d52c17c5a | |
parent | 7e1f90f27d876db67158ca4787420ec30c18f86b (diff) | |
download | cnp-go-0.2.0.tar.gz cnp-go-0.2.0.zip |
Update for CNP 0.4v0.2.0
-rw-r--r-- | cnp.go | 2 | ||||
-rw-r--r-- | header_test.go | 92 | ||||
-rw-r--r-- | message_test.go | 20 |
3 files changed, 57 insertions, 57 deletions
@@ -12,5 +12,5 @@ const ( VersionMajor = 0 // VersionMinor is the minor CNP version (Y in cnp/X.Y). - VersionMinor = 3 + VersionMinor = 4 ) diff --git a/header_test.go b/header_test.go index b035078..9b984ec 100644 --- a/header_test.go +++ b/header_test.go @@ -79,71 +79,71 @@ var headers = map[string]struct { e error }{ // invalid version - "cnp/0.3ok\n": {e: ErrorSyntax{}}, - "cwp/0.3 ok\n": {e: ErrorSyntax{}}, - "cnp/0.03 ok\n": {e: ErrorSyntax{}}, - "cnp/00.3 ok\n": {e: ErrorSyntax{}}, - "cnp/0..3 ok\n": {e: ErrorSyntax{}}, - "cnp/.3 ok\n": {e: ErrorSyntax{}}, + "cnp/0.4ok\n": {e: ErrorSyntax{}}, + "cwp/0.4 ok\n": {e: ErrorSyntax{}}, + "cnp/0.04 ok\n": {e: ErrorSyntax{}}, + "cnp/00.4 ok\n": {e: ErrorSyntax{}}, + "cnp/0..4 ok\n": {e: ErrorSyntax{}}, + "cnp/.4 ok\n": {e: ErrorSyntax{}}, "cnp/0. ok\n": {e: ErrorSyntax{}}, "cnp/. ok\n": {e: ErrorSyntax{}}, - "cnp/0,3 ok\n": {e: ErrorSyntax{}}, - "/0.3 ok\n": {e: ErrorSyntax{}}, - "0.3 ok\n": {e: ErrorSyntax{}}, + "cnp/0,4 ok\n": {e: ErrorSyntax{}}, + "/0.4 ok\n": {e: ErrorSyntax{}}, + "0.4 ok\n": {e: ErrorSyntax{}}, "cnp/ ok\n": {e: ErrorSyntax{}}, "cnp ok\n": {e: ErrorSyntax{}}, - "cnp.0.3 ok\n": {e: ErrorSyntax{}}, - "cnp/03 ok\n": {e: ErrorSyntax{}}, - "cnp/3 ok\n": {e: ErrorSyntax{}}, + "cnp.0.4 ok\n": {e: ErrorSyntax{}}, + "cnp/04 ok\n": {e: ErrorSyntax{}}, + "cnp/4 ok\n": {e: ErrorSyntax{}}, "cnp/0 ok\n": {e: ErrorSyntax{}}, - "cnp/0 3 ok\n": {e: ErrorSyntax{}}, - "cnp/0/3 ok\n": {e: ErrorSyntax{}}, + "cnp/0 4 ok\n": {e: ErrorSyntax{}}, + "cnp/0/4 ok\n": {e: ErrorSyntax{}}, // missing/invalid intent - "cnp/0.3\n": {e: ErrorSyntax{}}, - "cnp/0.3 \n": {e: ErrorSyntax{}}, - "cnp/0.3 o\x00k\n": {e: ErrorSyntax{}}, - "cnp/0.3 foo=bar\n": {e: ErrorSyntax{}}, + "cnp/0.4\n": {e: ErrorSyntax{}}, + "cnp/0.4 \n": {e: ErrorSyntax{}}, + "cnp/0.4 o\x00k\n": {e: ErrorSyntax{}}, + "cnp/0.4 foo=bar\n": {e: ErrorSyntax{}}, // missing/invalid line end - "cnp/0.3 ok \n": {e: ErrorSyntax{}}, - "cnp/0.3 ok\n\n": {e: ErrorSyntax{}}, - "cnp/0.3 ok": {e: ErrorSyntax{}}, - "cnp/0.3 ok ": {e: ErrorSyntax{}}, - "cnp/0.3 ok foo=bar \n": {e: ErrorSyntax{}}, - "cnp/0.3 ok foo=bar": {e: ErrorSyntax{}}, - "cnp/0.3 ok = =\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok \n": {e: ErrorSyntax{}}, + "cnp/0.4 ok\n\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok": {e: ErrorSyntax{}}, + "cnp/0.4 ok ": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo=bar \n": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo=bar": {e: ErrorSyntax{}}, + "cnp/0.4 ok = =\n": {e: ErrorSyntax{}}, // spaces - "cnp/0.3 ok foo=bar\n": {e: ErrorSyntax{}}, - "cnp/0.3 ok\n": {e: ErrorSyntax{}}, - "cnp/0.3\tok\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo=bar\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok\n": {e: ErrorSyntax{}}, + "cnp/0.4\tok\n": {e: ErrorSyntax{}}, // invalid params - "cnp/0.3 ok foo==bar\n": {e: ErrorSyntax{}}, - "cnp/0.3 ok foo=bar=baz\n": {e: ErrorSyntax{}}, - "cnp/0.3 ok foo=bar baz=quux \n": {e: ErrorSyntax{}}, - "cnp/0.3 ok foo\\-bar\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo==bar\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo=bar=baz\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo=bar baz=quux \n": {e: ErrorSyntax{}}, + "cnp/0.4 ok foo\\-bar\n": {e: ErrorSyntax{}}, // invalid escape sequences - "cnp/0.3 o\\k\n": {e: ErrorSyntax{}}, - "cnp/0.3 ok qwe=\\\n": {e: ErrorSyntax{}}, - "cnp/0.3 ok fo\\o=bar\n": {e: ErrorSyntax{}}, + "cnp/0.4 o\\k\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok qwe=\\\n": {e: ErrorSyntax{}}, + "cnp/0.4 ok fo\\o=bar\n": {e: ErrorSyntax{}}, // valid "cnp/0.0 ok\n": {h: Header{0, 0, "ok", nil}}, - "cnp/0.3 ok\n": {h: Header{0, 3, "ok", nil}}, + "cnp/0.4 ok\n": {h: Header{0, 4, "ok", nil}}, "cnp/1.0 ok\n": {h: Header{1, 0, "ok", nil}}, "cnp/123456.987654 ok\n": {h: Header{123456, 987654, "ok", nil}}, "cnp/0.1 ok\n": {h: Header{0, 1, "ok", nil}}, - "cnp/0.3 ok\r\n": {h: Header{0, 3, "ok\r", nil}}, - "cnp/0.3 foo\\nbar\n": {h: Header{0, 3, "foo\nbar", nil}}, - "cnp/0.3 \\-\\_\\n\\0\\\\\n": {h: Header{0, 3, "= \n\x00\\", nil}}, + "cnp/0.4 ok\r\n": {h: Header{0, 4, "ok\r", nil}}, + "cnp/0.4 foo\\nbar\n": {h: Header{0, 4, "foo\nbar", nil}}, + "cnp/0.4 \\-\\_\\n\\0\\\\\n": {h: Header{0, 4, "= \n\x00\\", nil}}, // valid with params - "cnp/0.3 ok type=text/plain\n": {h: Header{0, 3, "ok", Parameters{"type": "text/plain"}}}, - "cnp/0.3 ok baz=quux foo=bar qwe=asd\n": {h: Header{0, 3, "ok", Parameters{"foo": "bar", "baz": "quux", "qwe": "asd"}}}, - "cnp/0.3 ok = \\_=\\0 \\-=\\n\r\n": {h: Header{0, 3, "ok", Parameters{"": "", "=": "\n\r", " ": "\x00"}}}, + "cnp/0.4 ok type=text/plain\n": {h: Header{0, 4, "ok", Parameters{"type": "text/plain"}}}, + "cnp/0.4 ok baz=quux foo=bar qwe=asd\n": {h: Header{0, 4, "ok", Parameters{"foo": "bar", "baz": "quux", "qwe": "asd"}}}, + "cnp/0.4 ok = \\_=\\0 \\-=\\n\r\n": {h: Header{0, 4, "ok", Parameters{"": "", "=": "\n\r", " ": "\x00"}}}, } func TestHeaderParse(t *testing.T) { @@ -176,8 +176,8 @@ func TestHeaderCompose(t *testing.T) { } func TestNewHeader(t *testing.T) { - raw := "cnp/0.3 ok baz=quux foo=bar qwe=asd\n" - hdr := Header{0, 3, "ok", Parameters{"foo": "bar", "baz": "quux", "qwe": "asd"}} + raw := "cnp/0.4 ok baz=quux foo=bar qwe=asd\n" + hdr := Header{0, 4, "ok", Parameters{"foo": "bar", "baz": "quux", "qwe": "asd"}} h := NewHeader("ok", Parameters{"foo": "bar", "baz": "quux", "qwe": "asd"}) if !headerEqual(hdr, h) { t.Errorf("%+v: expected %+v", h, hdr) @@ -187,8 +187,8 @@ func TestNewHeader(t *testing.T) { t.Errorf("%q: expected %q", h, hdr) } - raw = "cnp/0.3 ok\n" - hdr = Header{0, 3, "ok", nil} + raw = "cnp/0.4 ok\n" + hdr = Header{0, 4, "ok", nil} h = NewHeader("ok", nil) if !headerEqual(hdr, h) { t.Errorf("%+v: expected %+v", h, hdr) diff --git a/message_test.go b/message_test.go index 1a73fa5..ebb8b7b 100644 --- a/message_test.go +++ b/message_test.go @@ -12,11 +12,11 @@ var ( messageTests = []messageTest{ { "qweasd", "text/plain", nil, nil, - "cnp/0.3 test1 length=6 type=text/plain\nqweasd", + "cnp/0.4 test1 length=6 type=text/plain\nqweasd", &Message{ Header: Header{ VersionMajor: 0, - VersionMinor: 3, + VersionMinor: 4, Intent: "test1", Parameters: Parameters{ "type": "text/plain", @@ -29,11 +29,11 @@ var ( { "qweasd", "text", nil, ErrorInvalid{}, - "cnp/0.3 test2 length=w type=text/plain\nqweasd", + "cnp/0.4 test2 length=w type=text/plain\nqweasd", &Message{ Header: Header{ VersionMajor: 0, - VersionMinor: 3, + VersionMinor: 4, Intent: "test2", Parameters: Parameters{ "type": "text/plain", @@ -46,17 +46,17 @@ var ( { "", "text/plain", ErrorSyntax{}, nil, - "cnp/0.3 test3 type=text/plain", + "cnp/0.4 test3 type=text/plain", nil, }, { "", "text/plain", nil, nil, - "cnp/0.3 test4 type=text/plain\n", + "cnp/0.4 test4 type=text/plain\n", &Message{ Header: Header{ VersionMajor: 0, - VersionMinor: 3, + VersionMinor: 4, Intent: "test4", Parameters: Parameters{ "type": "text/plain", @@ -157,7 +157,7 @@ func TestComputeLength(t *testing.T) { } func TestParseTooLarge(t *testing.T) { - s := "cnp/0.3 ok text=" + s := "cnp/0.4 ok text=" str := s + strings.Repeat(".", MaxHeaderLength-len(s)) + "\n" _, err := ParseMessage(strings.NewReader(str)) if _, ok := err.(ErrorTooLarge); !ok { @@ -180,13 +180,13 @@ func (n *noopCloser) Read(b []byte) (int, error) { } func TestClose(t *testing.T) { - var r io.Reader = strings.NewReader("cnp/0.3 ok\nqweasd") + var r io.Reader = strings.NewReader("cnp/0.4 ok\nqweasd") if msg, err := ParseMessage(r); err != nil { t.Errorf("ParseMessage error: %v", err) } else if err = msg.Close(); err != nil { t.Errorf("Error closing message: %v", err) } - r = &noopCloser{r: strings.NewReader("cnp/0.3 ok\nqweasd")} + r = &noopCloser{r: strings.NewReader("cnp/0.4 ok\nqweasd")} if msg, err := ParseMessage(r); err != nil { t.Errorf("ParseMessage error: %v", err) } else if err = msg.Close(); err != nil { |