@@ -95,7 +95,7 @@ func TestStateReaderHCL(t *testing.T) {
95
95
require .NoError (t , os .Mkdir (p , 0755 ))
96
96
97
97
// Write an empty schema file into the directory.
98
- os .WriteFile (p + "/schema.hcl" , []byte (`
98
+ require . NoError ( t , os .WriteFile (p + "/schema.hcl" , []byte (`
99
99
schema "default" {}
100
100
table "t1" {
101
101
schema = schema.default
@@ -105,7 +105,7 @@ table "t1" {
105
105
column "name" {
106
106
type = text
107
107
}
108
- }` ), 0644 )
108
+ }` ), 0644 ))
109
109
110
110
// Read schema file.
111
111
u , err := url .Parse ("file://" + p + "/schema.hcl" )
@@ -140,4 +140,32 @@ table "t1" {
140
140
require .NoError (t , err )
141
141
_ , exists := r .Schemas [0 ].Tables [0 ].Column ("name" )
142
142
require .False (t , exists , "column 'name' should be excluded" )
143
+
144
+ // Mimic multi-schema file.
145
+ // Write an empty schema file into the directory.
146
+ require .NoError (t , os .WriteFile (p + "/schema.hcl" , []byte (`
147
+ schema "main" {}
148
+ schema "default" {}
149
+ table "t1" {
150
+ schema = schema.default
151
+ column "id" {
152
+ type = int
153
+ }
154
+ column "name" {
155
+ type = text
156
+ }
157
+ }` ), 0644 ))
158
+ sr , err = StateReaderHCL (ctx , & StateReaderConfig {
159
+ Dev : dev ,
160
+ URLs : []* url.URL {u },
161
+ })
162
+ require .EqualError (t , err , `cannot use HCL with more than 1 schema when dev-url is limited to schema "main"` )
163
+ require .Nil (t , sr )
164
+
165
+ sr , err = StateReaderHCL (ctx , & StateReaderConfig {
166
+ Client : dev ,
167
+ URLs : []* url.URL {u },
168
+ })
169
+ require .EqualError (t , err , `cannot use HCL with more than 1 schema when url is limited to schema "main"` )
170
+ require .Nil (t , sr )
143
171
}
0 commit comments