@@ -26,11 +26,10 @@ import (
2626 "testing"
2727 "time"
2828
29- "vitess.io/vitess/go/vt/log"
30-
3129 "github.com/hashicorp/consul/api"
3230
3331 "vitess.io/vitess/go/testfiles"
32+ "vitess.io/vitess/go/vt/log"
3433 "vitess.io/vitess/go/vt/topo"
3534 "vitess.io/vitess/go/vt/topo/test"
3635
@@ -297,25 +296,42 @@ func TestConsulTopoWithAuthFailure(t *testing.T) {
297296
298297 consulAuthClientStaticFile = tmpFile .Name ()
299298
300- jsonConfig := "{\" global\" :{\" acl_token\" :\" badtoken\" }}"
301- if err := os .WriteFile (tmpFile .Name (), []byte (jsonConfig ), 0600 ); err != nil {
302- t .Fatalf ("couldn't write temp file: %v" , err )
303- }
299+ // check valid, empty json causes error
300+ {
301+ jsonConfig := "{}"
302+ if err := os .WriteFile (tmpFile .Name (), []byte (jsonConfig ), 0600 ); err != nil {
303+ t .Fatalf ("couldn't write temp file: %v" , err )
304+ }
304305
305- // Create the server on the new root.
306- ts , err := topo .OpenServer ("consul" , serverAddr , path .Join ("globalRoot" , topo .GlobalCell ))
307- if err != nil {
308- t .Fatalf ("OpenServer() failed: %v" , err )
306+ // Create the server on the new root.
307+ _ , err := topo .OpenServer ("consul" , serverAddr , path .Join ("globalRoot" , topo .GlobalCell ))
308+ if err == nil {
309+ t .Fatal ("Expected OpenServer() to return an error due to bad config, got nil" )
310+ }
309311 }
310312
311- // Attempt to Create the CellInfo.
312- err = ts .CreateCellInfo (context .Background (), test .LocalCellName , & topodatapb.CellInfo {
313- ServerAddress : serverAddr ,
314- Root : path .Join ("globalRoot" , test .LocalCellName ),
315- })
313+ // check bad token causes error
314+ {
315+ jsonConfig := "{\" global\" :{\" acl_token\" :\" badtoken\" }}"
316+ if err := os .WriteFile (tmpFile .Name (), []byte (jsonConfig ), 0600 ); err != nil {
317+ t .Fatalf ("couldn't write temp file: %v" , err )
318+ }
319+
320+ // Create the server on the new root.
321+ ts , err := topo .OpenServer ("consul" , serverAddr , path .Join ("globalRoot" , topo .GlobalCell ))
322+ if err != nil {
323+ t .Fatalf ("OpenServer() failed: %v" , err )
324+ }
325+
326+ // Attempt to Create the CellInfo.
327+ err = ts .CreateCellInfo (context .Background (), test .LocalCellName , & topodatapb.CellInfo {
328+ ServerAddress : serverAddr ,
329+ Root : path .Join ("globalRoot" , test .LocalCellName ),
330+ })
316331
317- want := "Failed request: ACL not found"
318- if err == nil || err .Error () != want {
319- t .Errorf ("Expected CreateCellInfo to fail: got %v, want %s" , err , want )
332+ want := "Failed request: ACL not found"
333+ if err == nil || err .Error () != want {
334+ t .Errorf ("Expected CreateCellInfo to fail: got %v, want %s" , err , want )
335+ }
320336 }
321337}
0 commit comments