github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/cmd/connect_test.go (about) 1 package cmd 2 3 import ( 4 "context" 5 "fmt" 6 "net/url" 7 "strings" 8 "testing" 9 "time" 10 11 regmock "github.com/qri-io/qri/registry/regserver" 12 ) 13 14 func TestConnect(t *testing.T) { 15 t.Skip("TODO(b5): this test is too flaky") 16 if err := confirmQriNotRunning(); err != nil { 17 t.Skip(err.Error()) 18 } 19 20 // Setup the test repo so that connect can run 21 run := NewTestRunner(t, "test_peer_qri_test_connect", "qri_test_connect") 22 defer run.Delete() 23 24 // Construct a mock registry to pass to the connect command 25 _, registryServer := regmock.NewMockServer() 26 27 // TODO(b5): this is supposed to free up ports, but locks when not completely disabled: 28 run.MustExec(t, "qri config set api.enabled false rpc.enabled false") 29 // Configure ports such that other tests do not conflict with the connection ports 30 // run.MustExec(t, "qri config set api.address /ip4/127.0.0.1/tcp/0 api.websocketaddress /ip4/127.0.0.1/tcp/0 rpc.address /ip4/127.0.0.1/tcp/0") 31 32 u, _ := url.Parse(registryServer.URL) 33 34 cmd := "qri connect --registry=" + fmt.Sprintf("/ip4/127.0.0.1/tcp/%s", strings.Split(u.Host, ":")[1]) 35 36 defer func() { 37 if e := recover(); e != nil { 38 t.Errorf("unexpected panic:\n%s\n%s", cmd, e) 39 return 40 } 41 }() 42 43 // Run the command for 1 second 44 ctx, done := context.WithTimeout(context.Background(), time.Second) 45 defer done() 46 47 err := run.ExecCommandWithContext(ctx, cmd) 48 if err != nil { 49 t.Errorf("unexpected error executing command\n%s\n%s", cmd, err.Error()) 50 return 51 } 52 }