Demo some examples in *nix.
[stompngo_examples.git] / sngecomm / utilities_test.go
blobdb255c972fc743c3457ec7c6529dfc016fdddf51
1 //
2 // Copyright © 2016 Guy M. Allard
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
17 package sngecomm
19 import (
20 "os"
21 "testing"
22 // "github.com/gmallard/stompngo"
25 type headersData struct {
26 key string
27 value string
30 var headersTests10 = []headersData{
31 {"login", "guest"},
32 {"passcode", "guest"},
35 var headersTests1x = []headersData{
36 {"login", "guest"},
37 {"passcode", "guest"},
38 {"accept-version", "1.1"},
39 {"host", "testhost"},
40 {"heart-beat", "100,500"},
44 Test utilities defaults. Must run with no environment variables set.
46 func TestConnectHeaders10(t *testing.T) {
47 h := ConnectHeaders()
48 for _, v := range headersTests10 {
49 val, ok := h.Contains(v.key)
50 if !ok {
51 t.Errorf("missing key [%s], expected [%t], got [%t]\n",
52 v.key, true, ok)
55 if v.value != val {
56 t.Errorf("incorrect value, expected [%s], got [%s]\n",
57 v.value, val)
63 Test utilities.
65 func TestConnectHeaders1x(t *testing.T) {
67 _ = os.Setenv("STOMP_HOST", "testhost")
68 _ = os.Setenv("STOMP_PROTOCOL", "1.1")
69 _ = os.Setenv("STOMP_HEARTBEATS", "100,500")
71 h := ConnectHeaders()
72 for _, v := range headersTests1x {
73 val, ok := h.Contains(v.key)
74 if !ok {
75 t.Errorf("missing key [%s], expected [%t], got [%t]\n",
76 v.key, true, ok)
79 if v.value != val {
80 t.Errorf("incorrect value, expected [%s], got [%s]\n",
81 v.value, val)