restructure test
This commit is contained in:
		| @@ -15,8 +15,8 @@ func TestFunction(t *testing.T) { | |||||||
|  |  | ||||||
| 	// create service | 	// create service | ||||||
| 	fn := NewFunction( | 	fn := NewFunction( | ||||||
| 		Name("test.function"), |  | ||||||
| 		Registry(mock.NewRegistry()), | 		Registry(mock.NewRegistry()), | ||||||
|  | 		Name("test.function"), | ||||||
| 		AfterStart(func() error { | 		AfterStart(func() error { | ||||||
| 			wg.Done() | 			wg.Done() | ||||||
| 			return nil | 			return nil | ||||||
| @@ -26,7 +26,13 @@ func TestFunction(t *testing.T) { | |||||||
| 	// we can't test fn.Init as it parses the command line | 	// we can't test fn.Init as it parses the command line | ||||||
| 	// fn.Init() | 	// fn.Init() | ||||||
|  |  | ||||||
|  | 	ch := make(chan error, 2) | ||||||
|  |  | ||||||
| 	go func() { | 	go func() { | ||||||
|  | 		// run service | ||||||
|  | 		ch <- fn.Run() | ||||||
|  | 	}() | ||||||
|  |  | ||||||
| 	// wait for start | 	// wait for start | ||||||
| 	wg.Wait() | 	wg.Wait() | ||||||
|  |  | ||||||
| @@ -47,10 +53,8 @@ func TestFunction(t *testing.T) { | |||||||
| 	if rsp.Status != "ok" { | 	if rsp.Status != "ok" { | ||||||
| 		t.Fatalf("function response: %s", rsp.Status) | 		t.Fatalf("function response: %s", rsp.Status) | ||||||
| 	} | 	} | ||||||
| 	}() |  | ||||||
|  |  | ||||||
| 	// run service | 	if err := <-ch; err != nil { | ||||||
| 	if err := fn.Run(); err != nil { |  | ||||||
| 		t.Fatal(err) | 		t.Fatal(err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user