forked from microsoft/kiota-abstractions-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_client_builder_test.go
64 lines (50 loc) · 2.88 KB
/
api_client_builder_test.go
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
package abstractions
import (
"fmt"
"reflect"
"testing"
"time"
"github.com/microsoft/kiota-abstractions-go/store"
"github.com/microsoft/kiota-abstractions-go/internal"
serialization "github.com/microsoft/kiota-abstractions-go/serialization"
assert "github.com/stretchr/testify/assert"
)
func TestItCreatesClientConcurrently(t *testing.T) {
metaFactory := func() serialization.SerializationWriterFactory {
return &internal.MockSerializerFactory{}
}
for i := 0; i < 1000; i++ {
go RegisterDefaultSerializer(metaFactory)
}
waitTime, _ := time.ParseDuration("100ms") // otherwise the routines might not be completed
time.Sleep(waitTime)
assert.Equal(t, 1, len(serialization.DefaultSerializationWriterFactoryInstance.ContentTypeAssociatedFactories))
serialization.DefaultSerializationWriterFactoryInstance.ContentTypeAssociatedFactories = make(map[string]serialization.SerializationWriterFactory)
}
func TestEnableBackingStoreForSerializationWriterFactory(t *testing.T) {
serializationFactoryRegistry := serialization.DefaultSerializationWriterFactoryInstance
factory := &internal.MockSerializerFactory{}
StreamContentType := "application/octet-stream"
serializationFactoryRegistry.ContentTypeAssociatedFactories[StreamContentType] = factory
IsNotType(t, &store.BackingStoreSerializationWriterProxyFactory{}, serializationFactoryRegistry.ContentTypeAssociatedFactories[StreamContentType])
EnableBackingStoreForSerializationWriterFactory(factory)
assert.IsType(t, &store.BackingStoreSerializationWriterProxyFactory{}, serializationFactoryRegistry.ContentTypeAssociatedFactories[StreamContentType])
serialization.DefaultSerializationWriterFactoryInstance.ContentTypeAssociatedFactories = make(map[string]serialization.SerializationWriterFactory)
}
func TestEnableBackingStoreForParseNodeFactory(t *testing.T) {
parseNodeRegistry := serialization.DefaultParseNodeFactoryInstance
factory := internal.NewMockParseNodeFactory()
StreamContentType := "application/octet-stream"
parseNodeRegistry.ContentTypeAssociatedFactories[StreamContentType] = factory
IsNotType(t, &store.BackingStoreParseNodeFactory{}, parseNodeRegistry.ContentTypeAssociatedFactories[StreamContentType])
EnableBackingStoreForParseNodeFactory(factory)
assert.IsType(t, &store.BackingStoreParseNodeFactory{}, parseNodeRegistry.ContentTypeAssociatedFactories[StreamContentType])
serialization.DefaultParseNodeFactoryInstance.ContentTypeAssociatedFactories = make(map[string]serialization.ParseNodeFactory)
}
// IsType asserts that the specified objects are of the same type.
func IsNotType(t assert.TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
if assert.ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType)) {
return assert.Fail(t, fmt.Sprintf("Object expected to be of type %v, but was %v", reflect.TypeOf(expectedType), reflect.TypeOf(object)), msgAndArgs...)
}
return true
}