@@ -14,135 +14,139 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
14
14
}
15
15
16
16
Describe " $CommandName Integration Tests" - Tag " IntegrationTests" {
17
- AfterAll {
18
- # TODO: WARNING: [12:43:16][Invoke-DbaQuery] [CLIENT\SQLInstance2] Failed during execution | Cannot drop the table 'CommaSeparatedWithHeader', because it does not exist or you do not have permission.
19
- Invoke-DbaQuery - SqlInstance $TestConfig.instance1 , $TestConfig.instance2 - Database tempdb - Query " drop table SuperSmall; drop table CommaSeparatedWithHeader"
17
+ BeforeAll {
18
+ $pathSuperSmall = " $ ( $TestConfig.appveyorlabrepo ) \csv\SuperSmall.csv"
19
+ $pathCommaSeparatedWithHeader = " $ ( $TestConfig.appveyorlabrepo ) \csv\CommaSeparatedWithHeader.csv"
20
+ $pathCols = " $ ( $TestConfig.appveyorlabrepo ) \csv\cols.csv"
21
+ $pathCol2 = " $ ( $TestConfig.appveyorlabrepo ) \csv\col2.csv"
22
+ $pathPipe3 = " $ ( $TestConfig.appveyorlabrepo ) \csv\pipe3.psv"
20
23
}
21
24
22
- $path = " $ ( $TestConfig.appveyorlabrepo ) \csv\SuperSmall.csv"
23
- $CommaSeparatedWithHeader = " $ ( $TestConfig.appveyorlabrepo ) \csv\CommaSeparatedWithHeader.csv"
24
- $col1 = " $ ( $TestConfig.appveyorlabrepo ) \csv\cols.csv"
25
- $col2 = " $ ( $TestConfig.appveyorlabrepo ) \csv\col2.csv"
26
- $pipe3 = " $ ( $TestConfig.appveyorlabrepo ) \csv\pipe3.psv"
27
-
25
+ AfterAll {
26
+ Get-DbaDbTable - SqlInstance $TestConfig.instance1 , $TestConfig.instance2 - Database tempdb - Table SuperSmall, CommaSeparatedWithHeader | Remove-DbaDbTable - Confirm:$false
27
+ }
28
28
29
29
Context " Works as expected" {
30
- $results = $path | Import-DbaCsv - SqlInstance $TestConfig.instance1 - Database tempdb - Delimiter `t - NotifyAfter 50000 - WarningVariable warn - WarningAction SilentlyContinue
31
- # TODO: Test for "Table or view SuperSmall does not exist and AutoCreateTable was not specified"
32
30
It " accepts piped input and doesn't add rows if the table does not exist" {
33
- $results | Should - Be $null
31
+ $results = $pathSuperSmall | Import-DbaCsv - SqlInstance $TestConfig.instance1 - Database tempdb - Delimiter `t - NotifyAfter 50000 - WarningVariable WarnVar - WarningAction SilentlyContinue
32
+
33
+ $WarnVar | Should - BeLike " *Table or view SuperSmall does not exist and AutoCreateTable was not specified*"
34
+ $results | Should - BeNullOrEmpty
34
35
}
35
36
36
37
It " creates the right columnmap (#7630), handles pipe delimiters (#7806)" {
37
- $null = Import-DbaCsv - SqlInstance $TestConfig.instance1 - Path $col1 - Database tempdb - AutoCreateTable - Table cols
38
- $null = Import-DbaCsv - SqlInstance $TestConfig.instance1 - Path $col2 - Database tempdb - Table cols
39
- $null = Import-DbaCsv - SqlInstance $TestConfig.instance1 - Path $pipe3 - Database tempdb - Table cols2 - Delimiter " |" - AutoCreateTable
38
+ $null = Import-DbaCsv - SqlInstance $TestConfig.instance1 - Path $pathCols - Database tempdb - AutoCreateTable - Table cols
39
+ $null = Import-DbaCsv - SqlInstance $TestConfig.instance1 - Path $pathCol2 - Database tempdb - Table cols
40
+ $null = Import-DbaCsv - SqlInstance $TestConfig.instance1 - Path $pathPipe3 - Database tempdb - Table cols2 - Delimiter " |" - AutoCreateTable
41
+
42
+
40
43
$results = Invoke-DbaQuery - SqlInstance $TestConfig.instance1 - Database tempdb - Query " select * from cols"
44
+
41
45
$results | Where-Object third -notmatch " three" | Should - BeNullOrEmpty
42
46
$results | Where-Object firstcol -notmatch " one" | Should - BeNullOrEmpty
47
+
48
+
43
49
$results = Invoke-DbaQuery - SqlInstance $TestConfig.instance1 - Database tempdb - Query " select * from cols2"
50
+
44
51
$results | Where-Object third -notmatch " three" | Should - BeNullOrEmpty
45
52
$results | Where-Object firstcol -notmatch " one" | Should - BeNullOrEmpty
46
53
}
47
54
48
- if (-not $env: appveyor ) {
49
- $results = Import-DbaCsv - Path $path , $path - SqlInstance $TestConfig.instance1 , $TestConfig.instance2 - Database tempdb - Delimiter `t - NotifyAfter 50000 - WarningVariable warn2 - AutoCreateTable
50
-
51
- It " performs 4 imports" {
52
- ($results ).Count | Should - Be 4
53
- }
55
+ It " performs 4 imports" {
56
+ $results = Import-DbaCsv - Path $pathSuperSmall , $pathSuperSmall - SqlInstance $TestConfig.instance1 , $TestConfig.instance2 - Database tempdb - Delimiter `t - NotifyAfter 50000 - WarningVariable warn2 - AutoCreateTable
54
57
58
+ ($results ).Count | Should - Be 4
55
59
foreach ($result in $results ) {
56
- It " returns the good stuff" {
57
- $result.RowsCopied | Should - Be 999
58
- $result.Database | Should - Be tempdb
59
- $result.Table | Should - Be SuperSmall
60
- }
61
- }
62
-
63
- $result = Import-DbaCsv - Path $path - SqlInstance $TestConfig.instance1 - Database tempdb - Delimiter `t - Table SuperSmall - Truncate
64
- It " doesn't break when truncate is passed" {
65
60
$result.RowsCopied | Should - Be 999
66
61
$result.Database | Should - Be tempdb
67
62
$result.Table | Should - Be SuperSmall
68
63
}
64
+ }
69
65
70
- $result = Import-DbaCsv - Path $path - SqlInstance $TestConfig.instance1 - Database tempdb - Delimiter `t - Table SuperSmall - Truncate - NoTransaction
71
- It " works with NoTransaction" {
72
- $result.RowsCopied | Should - Be 999
73
- $result.Database | Should - Be tempdb
74
- $result.Table | Should - Be SuperSmall
75
- }
66
+ It " doesn't break when truncate is passed" {
67
+ $result = Import-DbaCsv - Path $pathSuperSmall - SqlInstance $TestConfig.instance1 - Database tempdb - Delimiter `t - Table SuperSmall - Truncate
68
+
69
+ $result.RowsCopied | Should - Be 999
70
+ $result.Database | Should - Be tempdb
71
+ $result.Table | Should - Be SuperSmall
72
+ }
73
+
74
+ It " works with NoTransaction" {
75
+ $result = Import-DbaCsv - Path $pathSuperSmall - SqlInstance $TestConfig.instance1 - Database tempdb - Delimiter `t - Table SuperSmall - Truncate - NoTransaction
76
+
77
+ $result.RowsCopied | Should - Be 999
78
+ $result.Database | Should - Be tempdb
79
+ $result.Table | Should - Be SuperSmall
76
80
}
77
81
78
82
It " Catches the scenario where the database param does not match the server object passed into the command" {
79
- $server = Connect-DbaInstance $ TestConfig.instance1 - Database tempdb
80
- $result = Import-DbaCsv - Path $path - SqlInstance $server - Database InvalidDB - Delimiter `t - Table SuperSmall - Truncate - AutoCreateTable - WarningAction SilentlyContinue
81
- # TODO: test for Cannot open database "InvalidDB" requested by the login. The login failed.
83
+ $result = Import-DbaCsv - Path $pathSuperSmall - SqlInstance $ TestConfig.instance1 - Database InvalidDB - Delimiter `t - Table SuperSmall - Truncate - AutoCreateTable - WarningVariable WarnVar - WarningAction SilentlyContinue
84
+
85
+ $WarnVar | Should - BeLike " * Cannot open database * requested by the login. The login failed.* "
82
86
$result | Should - BeNullOrEmpty
83
87
84
- $server = Connect-DbaInstance $ TestConfig.instance1 - Database tempdb
85
- $result = Import-DbaCsv - Path $path - SqlInstance $server - Database tempdb - Delimiter `t - Table SuperSmall - Truncate - AutoCreateTable
88
+ $result = Import-DbaCsv - Path $pathSuperSmall - SqlInstance $ TestConfig.instance1 - Database tempdb - Delimiter `t - Table SuperSmall - Truncate - AutoCreateTable
89
+
86
90
$result.RowsCopied | Should - Be 999
87
91
$result.Database | Should - Be tempdb
88
92
$result.Table | Should - Be SuperSmall
89
93
}
90
94
91
95
It " Catches the scenario where the header is not properly parsed causing param errors" {
92
- # TODO: WARNING: [12:43:13][Invoke-DbaQuery] [CLIENT] Failed during execution | Cannot drop the table 'NoHeaderRow', because it does not exist or you do not have permission.
93
- # TODO: What line writes the warning? Is this correct?
94
-
95
96
# create the table using AutoCreate
96
- $server = Connect-DbaInstance $TestConfig.instance1 - Database tempdb
97
- $null = Import-DbaCsv - Path $CommaSeparatedWithHeader - SqlInstance $server - Database tempdb - AutoCreateTable
98
-
97
+ $null = Import-DbaCsv - Path $pathCommaSeparatedWithHeader - SqlInstance $TestConfig.instance1 - Database tempdb - AutoCreateTable
99
98
# reload table without AutoCreate parameter to recreate bug #6553
100
- $result = Import-DbaCsv - Path $CommaSeparatedWithHeader - SqlInstance $server - Database tempdb - Truncate
99
+ $result = Import-DbaCsv - Path $pathCommaSeparatedWithHeader - SqlInstance $TestConfig.instance1 - Database tempdb - Truncate
100
+
101
101
$result.RowsCopied | Should - Be 1
102
102
$result.Database | Should - Be tempdb
103
103
$result.Table | Should - Be CommaSeparatedWithHeader
104
- Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE NoHeaderRow'
104
+
105
+ Invoke-DbaQuery - SqlInstance $TestConfig.instance1 - Database tempdb - Query ' DROP TABLE CommaSeparatedWithHeader'
105
106
}
106
107
107
108
It " works with NoHeaderRow" {
108
109
# See #7759
109
110
$server = Connect-DbaInstance $TestConfig.instance1 - Database tempdb
110
111
Invoke-DbaQuery - SqlInstance $server - Query ' CREATE TABLE NoHeaderRow (c1 VARCHAR(50), c2 VARCHAR(50), c3 VARCHAR(50))'
111
- $result = Import-DbaCsv - Path $col1 - NoHeaderRow - SqlInstance $server - Database tempdb - Table ' NoHeaderRow' - WarningVariable warnNoHeaderRow
112
+
113
+ $result = Import-DbaCsv - Path $pathCols - NoHeaderRow - SqlInstance $server - Database tempdb - Table ' NoHeaderRow'
112
114
$data = Invoke-DbaQuery - SqlInstance $server - Query ' SELECT * FROM NoHeaderRow' -As PSObject
113
- Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE NoHeaderRow'
114
115
115
- $warnNoHeaderRow | Should - BeNullOrEmpty
116
- $result | Should -Not - BeNullOrEmpty
117
116
$result.RowsCopied | Should - Be 3
118
117
$data [0 ].c1 | Should - Be ' firstcol'
118
+
119
+ Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE NoHeaderRow'
119
120
}
120
121
121
122
It " works with tables which have non-varchar types (date)" {
122
123
# See #9433
123
124
$server = Connect-DbaInstance $TestConfig.instance1 - Database tempdb
124
125
Invoke-DbaQuery - SqlInstance $server - Query ' CREATE TABLE WithTypes ([date] DATE, col1 VARCHAR(50), col2 VARCHAR(50))'
125
- $result = Import-DbaCsv - Path $CommaSeparatedWithHeader - SqlInstance $server - Database tempdb - Table ' WithTypes'
126
- Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE WithTypes'
126
+ $result = Import-DbaCsv - Path $pathCommaSeparatedWithHeader - SqlInstance $server - Database tempdb - Table ' WithTypes'
127
127
128
128
$result | Should -Not - BeNullOrEmpty
129
129
$result.RowsCopied | Should - Be 1
130
+
131
+ Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE WithTypes'
130
132
}
131
133
132
134
It " works with tables which have non-varchar types (guid, bit)" {
133
135
# See #9433
134
- $filePath = ' . \foo.csv'
136
+ $filePath = " $ ( $TestConfig .Temp ) \foo.csv"
135
137
$server = Connect-DbaInstance $TestConfig.instance1 - Database tempdb
136
138
Invoke-DbaQuery - SqlInstance $server - Query ' CREATE TABLE WithGuidsAndBits (one_guid UNIQUEIDENTIFIER, one_bit BIT)'
137
139
$row = [pscustomobject ]@ {
138
140
one_guid = (New-Guid ).Guid
139
141
one_bit = 1
140
142
}
141
143
$row | Export-Csv - Path $filePath - NoTypeInformation
144
+
142
145
$result = Import-DbaCsv - Path $filePath - SqlInstance $server - Database tempdb - Table ' WithGuidsAndBits'
143
- Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE WithGuidsAndBits'
144
146
145
147
$result.RowsCopied | Should - Be 1
148
+
149
+ Invoke-DbaQuery - SqlInstance $server - Query ' DROP TABLE WithGuidsAndBits'
146
150
Remove-Item $filePath
147
151
}
148
152
}
0 commit comments