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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
package exports_test
import (
"reflect"
"testing"
"github.com/Azure/azure-sdk-for-go/eng/tools/internal/exports"
)
var pkg exports.Package
var exp exports.Content
func init() {
pkg, _ = exports.LoadPackage("./testdata")
exp = pkg.GetExports()
}
func Test_Constants(t *testing.T) {
if l := len(exp.Consts); l != 13 {
t.Logf("wrong number of constants, got %v", l)
t.Fail()
}
tests := []struct {
cn string
exports.Const
}{
{"DefaultBaseURI", exports.Const{Type: "string", Value: "https://management.azure.com"}},
{"Tuesday", exports.Const{Type: "DayOfWeek", Value: "Tuesday"}},
{"Primary", exports.Const{Type: "KeyType", Value: "Primary"}},
{"Backup", exports.Const{Type: "KeyType", Value: "Backup"}},
}
for _, test := range tests {
t.Run(test.cn, func(t *testing.T) {
c := exp.Consts[test.cn]
if !reflect.DeepEqual(c.Type, test.Type) {
t.Logf("mismatched types, %s != %s", c.Type, test.Type)
t.Fail()
}
if c.Value != test.Value {
t.Logf("mismatched values, %s != %s", c.Value, test.Value)
t.Fail()
}
})
}
}
func Test_Funcs(t *testing.T) {
if l := len(exp.Funcs); l != 21 {
t.Logf("wrong number of funcs, got %v", l)
t.Fail()
}
tests := []struct {
fn string
exports.Func
}{
{"DoNothing", exports.Func{}},
{"DoNothingWithParam", exports.Func{Params: strPtr("int"), Returns: nil}},
{"UserAgent", exports.Func{Params: nil, Returns: strPtr("string")}},
{"Client.Delete", exports.Func{Params: strPtr("context.Context, string, string"), Returns: strPtr("DeleteFuture, error")}},
{"Client.ListSender", exports.Func{Params: strPtr("*http.Request"), Returns: strPtr("*http.Response, error")}},
}
for _, test := range tests {
t.Run(test.fn, func(t *testing.T) {
f := exp.Funcs[test.fn]
if !reflect.DeepEqual(f.Params, test.Params) {
t.Logf("mismatched params, %s != %s", safeStr(f.Params), safeStr(test.Params))
t.Fail()
}
if !reflect.DeepEqual(f.Returns, test.Returns) {
t.Logf("mismatched returns, %s != %s", safeStr(f.Returns), safeStr(test.Returns))
t.Fail()
}
})
}
}
func Test_Interfaces(t *testing.T) {
if l := len(exp.Interfaces); l != 1 {
t.Logf("wrong number of interfaces, got %v", l)
t.Fail()
}
tests := []struct {
in string
exports.Interface
}{
{"SomeInterface", exports.Interface{
Methods: map[string]exports.Func{
"One": {
Params: nil,
Returns: nil,
},
"Two": {
Params: strPtr("bool"),
Returns: nil,
},
"Three": {
Params: nil,
Returns: strPtr("string"),
},
"Four": {
Params: strPtr("int"),
Returns: strPtr("error"),
},
"Five": {
Params: strPtr("int, bool"),
Returns: strPtr("int, error"),
},
},
}},
}
for _, test := range tests {
t.Run(test.in, func(t *testing.T) {
i := exp.Interfaces[test.in]
if !reflect.DeepEqual(i.Methods, test.Methods) {
t.Logf("mismatched methods, have %+v, want %+v", i.Methods, test.Methods)
t.Fail()
}
})
}
}
func Test_Structs(t *testing.T) {
if l := len(exp.Structs); l != 8 {
t.Logf("wrong number of structs, got %v", l)
t.Fail()
}
tests := []struct {
sn string
exports.Struct
}{
{"BaseClient", exports.Struct{
AnonymousFields: []string{"autorest.Client"},
Fields: map[string]string{
"BaseURI": "string",
"SubscriptionID": "string",
}}},
{"DeleteFuture", exports.Struct{
AnonymousFields: []string{"azure.Future"},
}},
{"ListResultPage", exports.Struct{}},
{"CreateParameters", exports.Struct{
AnonymousFields: []string{"*CreateProperties"},
Fields: map[string]string{
"Zones": "*[]string",
"Location": "*string",
"Tags": "map[string]*string",
}}},
{"CreateProperties", exports.Struct{
Fields: map[string]string{
"SubnetID": "*string",
"StaticIP": "*string",
"RedisConfiguration": "map[string]*string",
"EnableNonSslPort": "*bool",
"TenantSettings": "map[string]*string",
"ShardCount": "*int32",
}}},
}
for _, test := range tests {
t.Run(test.sn, func(t *testing.T) {
s := exp.Structs[test.sn]
if !reflect.DeepEqual(s.AnonymousFields, test.AnonymousFields) {
t.Logf("mismatched anonymous fields, have %+v, want %v", s.AnonymousFields, test.AnonymousFields)
t.Fail()
}
if !reflect.DeepEqual(s.Fields, test.Fields) {
t.Logf("mismatched fields, have %+v want %+v", s.Fields, test.Fields)
t.Fail()
}
})
}
}
func Test_Name(t *testing.T) {
if n := pkg.Name(); n != "testdata" {
t.Logf("incorrect package name, have '%s', want 'testdata'", n)
t.Fail()
}
}
func strPtr(s string) *string {
return &s
}
func safeStr(s *string) string {
if s == nil {
return "<nil>"
}
return *s
}
|