2 // Copyright © 2011-2016 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
26 Test Logger Basic, confirm by observation.
28 func TestLoggerBasic(t
*testing
.T
) {
30 ch
:= check11(TEST_HEADERS
)
31 conn
, _
:= Connect(n
, ch
)
33 l
:= log
.New(os
.Stdout
, "", log
.Ldate|log
.Lmicroseconds
)
36 _
= conn
.Disconnect(empty_headers
)
42 Test Logger with a zero Byte Message, a corner case. This is merely
43 to demonstrate the basics of log output when a logger is set for the
46 func TestLoggerMiscBytes0(t
*testing
.T
) {
47 ll
:= log
.New(os
.Stdout
, "TLM01 ", log
.Ldate|log
.Lmicroseconds|log
.Lshortfile
)
50 ch
:= check11(TEST_HEADERS
)
51 conn
, _
:= Connect(n
, ch
)
55 d
:= tdest("/queue/logger.zero.byte.msg")
56 sh
:= Headers
{HK_DESTINATION
, d
}
57 e
:= conn
.Send(sh
, ms
)
59 t
.Fatalf("Expected nil error, got [%v]\n", e
)
62 _
= conn
.Disconnect(empty_headers
)
67 ch
= check11(TEST_HEADERS
)
68 conn
, _
= Connect(n
, ch
)
69 ll
= log
.New(os
.Stdout
, "TLM02 ", log
.Ldate|log
.Lmicroseconds|log
.Lshortfile
)
72 sbh
:= sh
.Add(HK_ID
, d
)
73 sc
, e
:= conn
.Subscribe(sbh
)
75 t
.Fatalf("Expected no subscribe error, got [%v]\n", e
)
78 t
.Fatalf("Expected subscribe channel, got [nil]\n")
85 case md
= <-conn
.MessageData
:
86 t
.Fatalf("read channel error: expected [nil], got: [%v]\n",
91 t
.Fatalf("Expected no message data error, got [%v]\n", md
.Error
)
94 // The real tests here
95 if len(md
.Message
.Body
) != 0 {
96 t
.Fatalf("Expected body length 0, got [%v]\n", len(md
.Message
.Body
))
98 if string(md
.Message
.Body
) != ms
{
99 t
.Fatalf("Expected [%v], got [%v]\n", ms
, string(md
.Message
.Body
))
102 _
= conn
.Disconnect(empty_headers
)