@@ -52,7 +52,7 @@ func varsByName(vars []*variables.Variable) map[string]*variables.Variable {
5252 return out
5353}
5454
55- func TestConsulSource_Fetch_Integration (t * testing.T ) {
55+ func TestConsulSource_Fetch (t * testing.T ) {
5656 ci .Parallel (t )
5757
5858 srv := startTestConsul (t )
@@ -79,16 +79,6 @@ func TestConsulSource_Fetch_Integration(t *testing.T) {
7979 must .Eq (t , "us-west-2" , got ["region" ].Value .AsString ())
8080 })
8181
82- t .Run ("path is not modified" , func (t * testing.T ) {
83- srv .SetKVString (t , "ops/webapp/region" , "eu-central-1" )
84-
85- src := newSourceForServer (t , srv , "ops/webapp" )
86- vars , err := src .Fetch (t .Context (), packID , schema )
87- must .NoError (t , err )
88- must .Len (t , 1 , vars )
89- must .Eq (t , "eu-central-1" , varsByName (vars )["region" ].Value .AsString ())
90- })
91-
9282 t .Run ("keys not in pack schema are ignored" , func (t * testing.T ) {
9383 srv .SetKVString (t , "staging/webapp/region" , "us-east-1" )
9484 srv .SetKVString (t , "staging/webapp/not_in_pack" , "ignored" )
@@ -170,4 +160,34 @@ func TestConsulSource_Fetch_Integration(t *testing.T) {
170160 must .NoError (t , err )
171161 must .Len (t , 0 , vars )
172162 })
163+
164+ t .Run ("consul unavailable returns list error" , func (t * testing.T ) {
165+ cfg := api .DefaultConfig ()
166+ cfg .Address = "127.0.0.1:19998"
167+ src , err := NewConsulSource (PriorityConsul , cfg , "any/path" )
168+ must .NoError (t , err )
169+ _ , err = src .Fetch (t .Context (), packID , schema )
170+ must .ErrorContains (t , err , "failed to list Consul KV" )
171+ })
172+
173+ t .Run ("path with surrounding slashes fetches correctly" , func (t * testing.T ) {
174+ srv .SetKVString (t , "norm/webapp/region" , "ap-southeast-1" )
175+
176+ src := newSourceForServer (t , srv , "/norm/webapp/" )
177+ vars , err := src .Fetch (t .Context (), packID , schema )
178+ must .NoError (t , err )
179+ must .Len (t , 1 , vars )
180+ must .Eq (t , "ap-southeast-1" , varsByName (vars )["region" ].Value .AsString ())
181+ })
182+
183+ t .Run ("keys with trailing slash are skipped" , func (t * testing.T ) {
184+ srv .SetKVString (t , "nested/webapp/region" , "us-east-1" )
185+ srv .SetKVString (t , "nested/webapp/subdir/" , "ignored" )
186+
187+ src := newSourceForServer (t , srv , "nested/webapp" )
188+ vars , err := src .Fetch (t .Context (), packID , schema )
189+ must .NoError (t , err )
190+ must .Len (t , 1 , vars )
191+ must .Eq (t , "region" , string (vars [0 ].Name ))
192+ })
173193}
0 commit comments