@@ -52,7 +52,8 @@ final class ClickHouseVaporTests: XCTestCase {
52
52
static var allTests = [
53
53
( " testPing " , testPing) ,
54
54
( " testModel " , testModel) ,
55
- ( " testModelMissesColumns " , testModelMissesColumns)
55
+ ( " testDifferingRowsInsert " , testDifferingRowsInsert) ,
56
+ ( " testEmptyModelInsert " , testEmptyModelInsert)
56
57
]
57
58
58
59
func testPing( ) {
@@ -111,8 +112,8 @@ final class ClickHouseVaporTests: XCTestCase {
111
112
XCTAssertEqual ( model3. timestamp, model2. timestamp)
112
113
}
113
114
114
- /// model should fail if insert with empty columns is tried
115
- public func testModelMissesColumns ( ) {
115
+ /// insert should fail if some columns are not set, but others are
116
+ public func testDifferingRowsInsert ( ) {
116
117
let app = Application ( . testing)
117
118
defer { app. shutdown ( ) }
118
119
try ! app. configureClickHouseDatabases ( )
@@ -125,11 +126,40 @@ final class ClickHouseVaporTests: XCTestCase {
125
126
126
127
127
128
model. id = [ " x010 " , " ax51 " , " cd22 " ]
128
- model. fixed = [ " " , " 123456 " , " 12345678901234 " ]
129
+ model. fixed = [ " " , " 12345678901234 " ]
130
+ model. timestamp = [ 100 , 200 , 300 ]
129
131
model. temperature = [ 11.1 , 10.4 , 8.9 ]
130
132
131
133
try ! TestModel . createTable ( on: app. clickHouse) . wait ( )
132
- XCTAssertThrowsError ( try model. insert ( on: app. clickHouse) . wait ( ) , " \( ClickHouseVaporError . mismatchingRowCount ( count: 0 , expected: 3 ) ) " )
134
+
135
+ var thrownError : Error ?
136
+ // insert should fail if one tries to insert columns with different amount of rows
137
+ XCTAssertThrowsError ( try model. insert ( on: app. clickHouse) . wait ( ) ) {
138
+ thrownError = $0
139
+ }
140
+ // check that we get correct error message
141
+ XCTAssertEqual ( thrownError as! ClickHouseVaporError , ClickHouseVaporError . mismatchingRowCount ( count: 2 , expected: 3 ) )
142
+ }
143
+
144
+
145
+ /// insert should not fail if the complete model is empty
146
+ public func testEmptyModelInsert( ) {
147
+ let app = Application ( . testing)
148
+ defer { app. shutdown ( ) }
149
+ try ! app. configureClickHouseDatabases ( )
150
+ app. logger. logLevel = . trace
151
+
152
+ let model = TestModel ( )
153
+
154
+ // drop table to ensure unit test
155
+ try ! TestModel . deleteTable ( on: app. clickHouse) . wait ( )
156
+
157
+ try ! TestModel . createTable ( on: app. clickHouse) . wait ( )
158
+
159
+ // insert should not fail if all columns are empty
160
+ XCTAssertNoThrow ( try model. insert ( on: app. clickHouse) . wait ( ) )
133
161
}
162
+
163
+
134
164
135
165
}
0 commit comments