func newWithConfig(configPath string) (types.Client, error) { config := gofig.New() if err := config.ReadConfigFile(configPath); err != nil { return nil, err } return client.New(nil, config) }
func newClient( ctx apitypes.Context, config gofig.Config) (apitypes.Client, error) { return apiclient.New(ctx, config) }
func (th *testHarness) run( t *testing.T, clientType types.ClientType, driver string, configBuf []byte, debug, group bool, tests ...APITestFunc) { if !testing.Verbose() { buf := &bytes.Buffer{} log.StandardLogger().Out = buf defer func() { if t.Failed() { io.Copy(os.Stderr, buf) } }() } wg := &sync.WaitGroup{} if group { config := getTestConfig(t, clientType, configBuf, debug) configNames, configs := getTestConfigs(t, driver, config) for x, config := range configs { wg.Add(1) go func(x int, config gofig.Config) { defer wg.Done() server, errs, err := apiserver.Serve(nil, config) if err != nil { th.closeServers(t) t.Fatal(err) } go func() { err := <-errs if err != nil { th.closeServers(t) t.Fatalf("server (%s) error: %v", configNames[x], err) } }() th.servers = append(th.servers, server) c, err := client.New(nil, config) assert.NoError(t, err) assert.NotNil(t, c) if err != nil || c == nil { t.Fatalf("err=%v, client=%v", err, c) } for _, test := range tests { test(config, c, t) if t.Failed() && printConfigOnFail { cj, err := config.ToJSON() if err != nil { t.Fatal(err) } fmt.Printf("client.config=%s\n", cj) } } }(x, config) } } else { for _, test := range tests { config := getTestConfig(t, clientType, configBuf, debug) configNames, configs := getTestConfigs(t, driver, config) for x, config := range configs { wg.Add(1) go func(test APITestFunc, x int, config gofig.Config) { defer wg.Done() server, errs, err := apiserver.Serve(nil, config) if err != nil { th.closeServers(t) t.Fatal(err) } go func() { err := <-errs if err != nil { th.closeServers(t) t.Fatalf("server (%s) error: %v", configNames[x], err) } }() th.servers = append(th.servers, server) c, err := client.New(nil, config) if err != nil { t.Fatal(err) } assert.NoError(t, err) assert.NotNil(t, c) if c == nil { panic(fmt.Sprintf("err=%v, client=%v", err, c)) } test(config, c, t) if t.Failed() && printConfigOnFail { cj, err := config.ToJSON() if err != nil { t.Fatal(err) } fmt.Printf("client.config=%s\n", cj) } }(test, x, config) } } } wg.Wait() th.closeServers(t) }