1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// +build go1.8
package awssupport
import (
"net/http"
"strings"
"testing"
)
func TestGetTableName(t *testing.T) {
str := "this is a string"
var emptyStr string
strPtr := &str
emptyStrPtr := &emptyStr
testcases := []struct {
params interface{}
expected string
}{
{params: nil, expected: ""},
{params: str, expected: ""},
{params: strPtr, expected: ""},
{params: struct{ other string }{other: str}, expected: ""},
{params: &struct{ other string }{other: str}, expected: ""},
{params: struct{ TableName bool }{TableName: true}, expected: ""},
{params: &struct{ TableName bool }{TableName: true}, expected: ""},
{params: struct{ TableName string }{TableName: str}, expected: ""},
{params: &struct{ TableName string }{TableName: str}, expected: ""},
{params: struct{ TableName *string }{TableName: nil}, expected: ""},
{params: &struct{ TableName *string }{TableName: nil}, expected: ""},
{params: struct{ TableName *string }{TableName: emptyStrPtr}, expected: ""},
{params: &struct{ TableName *string }{TableName: emptyStrPtr}, expected: ""},
{params: struct{ TableName *string }{TableName: strPtr}, expected: ""},
{params: &struct{ TableName *string }{TableName: strPtr}, expected: str},
}
for i, test := range testcases {
if out := getTableName(test.params); test.expected != out {
t.Error(i, out, test.params, test.expected)
}
}
}
func TestGetRequestID(t *testing.T) {
primary := "X-Amzn-Requestid"
secondary := "X-Amz-Request-Id"
testcases := []struct {
hdr http.Header
expected string
}{
{hdr: http.Header{
"hello": []string{"world"},
}, expected: ""},
{hdr: http.Header{
strings.ToUpper(primary): []string{"hello"},
}, expected: ""},
{hdr: http.Header{
primary: []string{"hello"},
}, expected: "hello"},
{hdr: http.Header{
secondary: []string{"hello"},
}, expected: "hello"},
{hdr: http.Header{
primary: []string{"hello"},
secondary: []string{"world"},
}, expected: "hello"},
{hdr: http.Header{}, expected: ""},
}
for i, test := range testcases {
if out := GetRequestID(test.hdr); test.expected != out {
t.Error(i, out, test.hdr, test.expected)
}
}
}
|