-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsessionx_test.go
More file actions
154 lines (127 loc) · 4.14 KB
/
sessionx_test.go
File metadata and controls
154 lines (127 loc) · 4.14 KB
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
package gocqlxmock
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type sessionXSut struct {
ctx context.Context
stmt string
names []string
err error
errMsg string
sessionxmock *SessionxMock
querymock *QueryxMock
}
func makeSessionxSut() sessionXSut {
ctx := context.Background()
stmt := "statement"
names := []string{"name1", "name2"}
errMsg := "sessionx_error"
err := fmt.Errorf(errMsg)
sessionxmock := &SessionxMock{}
querymock := &QueryxMock{}
return sessionXSut{
ctx,
stmt,
names,
err,
errMsg,
sessionxmock,
querymock,
}
}
func Test_Sessionx_ContextQuery(t *testing.T) {
t.Run("Should call ContextQuery with proper parameters and return proper result", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("ContextQuery", sut.ctx, sut.stmt, sut.names).Return(sut.querymock)
// act
result := sut.sessionxmock.ContextQuery(sut.ctx, sut.stmt, sut.names)
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "ContextQuery", sut.ctx, sut.stmt, sut.names)
sut.sessionxmock.AssertNumberOfCalls(t, "ContextQuery", 1)
assert.Equal(t, result, sut.querymock)
})
}
func Test_Sessionx_Query(t *testing.T) {
t.Run("Should call Query with proper parameters and return proper result", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("Query", sut.stmt, sut.names).Return(sut.querymock)
// act
result := sut.sessionxmock.Query(sut.stmt, sut.names)
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "Query", sut.stmt, sut.names)
sut.sessionxmock.AssertNumberOfCalls(t, "Query", 1)
assert.Equal(t, result, sut.querymock)
})
}
func Test_Sessionx_ExecStmt(t *testing.T) {
t.Run("Should call ExecStmt with proper parameters and return proper result", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("ExecStmt", sut.stmt).Return(nil)
// act
result := sut.sessionxmock.ExecStmt(sut.stmt)
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "ExecStmt", sut.stmt)
sut.sessionxmock.AssertNumberOfCalls(t, "ExecStmt", 1)
assert.NoError(t, result)
})
t.Run("Should call ExecStmt with proper parameters and return error", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("ExecStmt", sut.stmt).Return(sut.err)
// act
result := sut.sessionxmock.ExecStmt(sut.stmt)
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "ExecStmt", sut.stmt)
sut.sessionxmock.AssertNumberOfCalls(t, "ExecStmt", 1)
assert.Error(t, result, sut.errMsg)
})
}
func Test_Sessionx_AwaitSchemaAgreement(t *testing.T) {
t.Run("Should call AwaitSchemaAgreement with proper parameters and return proper result", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("AwaitSchemaAgreement", sut.ctx).Return(nil)
// act
result := sut.sessionxmock.AwaitSchemaAgreement(sut.ctx)
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "AwaitSchemaAgreement", sut.ctx)
sut.sessionxmock.AssertNumberOfCalls(t, "AwaitSchemaAgreement", 1)
assert.NoError(t, result)
})
t.Run("Should call AwaitSchemaAgreement with proper parameters and return error", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("AwaitSchemaAgreement", sut.ctx).Return(sut.err)
// act
result := sut.sessionxmock.AwaitSchemaAgreement(sut.ctx)
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "AwaitSchemaAgreement", sut.ctx)
sut.sessionxmock.AssertNumberOfCalls(t, "AwaitSchemaAgreement", 1)
assert.Error(t, result, sut.errMsg)
})
}
func Test_Sessionx_Close(t *testing.T) {
t.Run("Should call Close with proper parameters and return void", func(t *testing.T) {
// arrange
sut := makeSessionxSut()
sut.sessionxmock.On("Close").Return()
// act
sut.sessionxmock.Close()
// assert
sut.sessionxmock.AssertExpectations(t)
sut.sessionxmock.AssertCalled(t, "Close")
sut.sessionxmock.AssertNumberOfCalls(t, "Close", 1)
})
}