func TestContextServices(t *testing.T) {
	stack, err := New(testNodeConfig())
	if err != nil {
		t.Fatalf("failed to create protocol stack: %v", err)
	}
	// Define a verifier that ensures a NoopA is before it and NoopB after
	verifier := func(ctx *ServiceContext) (Service, error) {
		var objA *NoopServiceA
		if ctx.Service(&objA) != nil {
			return nil, fmt.Errorf("former service not found")
		}
		var objB *NoopServiceB
		if err := ctx.Service(&objB); err != ErrServiceUnknown {
			return nil, fmt.Errorf("latters lookup error mismatch: have %v, want %v", err, ErrServiceUnknown)
		}
		return new(NoopService), nil
	}
	// Register the collection of services
	if err := stack.Register(NewNoopServiceA); err != nil {
		t.Fatalf("former failed to register service: %v", err)
	}
	if err := stack.Register(verifier); err != nil {
		t.Fatalf("failed to register service verifier: %v", err)
	}
	if err := stack.Register(NewNoopServiceB); err != nil {
		t.Fatalf("latter failed to register service: %v", err)
	}
	// Start the protocol stack and ensure services are constructed in order
	if err := stack.Start(); err != nil {
		t.Fatalf("failed to start stack: %v", err)
	}
	defer stack.Stop()
}
// Tests that already constructed services can be retrieves by later ones.
Tests that already constructed services can be retrieves by later ones.
// Tests that already constructed services can be retrieves by later ones .
func TestContextServices(t *testing.T) {
	stack, err := New(testNodeConfig())
	if err != nil {
		t.Fatalf("failed to create protocol stack: %v", err)
	}
	verifier := func(ctx *ServiceContext) (Service, error) {
		var objA *NoopServiceA
		if ctx.Service(&objA) != nil {
			return nil, fmt.Errorf("former service not found")
		}
		var objB *NoopServiceB
		if err := ctx.Service(&objB); err != ErrServiceUnknown {
			return nil, fmt.Errorf("latters lookup error mismatch: have %v, want %v", err, ErrServiceUnknown)
		}
		return new(NoopService), nil
	}
	if err := stack.Register(NewNoopServiceA); err != nil {
		t.Fatalf("former failed to register service: %v", err)
	}
	if err := stack.Register(verifier); err != nil {
		t.Fatalf("failed to register service verifier: %v", err)
	}
	if err := stack.Register(NewNoopServiceB); err != nil {
		t.Fatalf("latter failed to register service: %v", err)
	}
	if err := stack.Start(); err != nil {
		t.Fatalf("failed to start stack: %v", err)
	}
	defer stack.Stop()
}
func TestContextServices ( t * testing . T ) { stack , err := New ( testNodeConfig ( ) ) if err != nil { t . Fatalf ( " " , err ) } verifier := func ( ctx * ServiceContext ) ( Service , error ) { var objA * NoopServiceA if ctx . Service ( & objA ) != nil { return nil , fmt . Errorf ( " " ) } var objB * NoopServiceB if err := ctx . Service ( & objB ) ; err != ErrServiceUnknown { return nil , fmt . Errorf ( " " , err , ErrServiceUnknown ) } return new ( NoopService ) , nil } if err := stack . Register ( NewNoopServiceA ) ; err != nil { t . Fatalf ( " " , err ) } if err := stack . Register ( verifier ) ; err != nil { t . Fatalf ( " " , err ) } if err := stack . Register ( NewNoopServiceB ) ; err != nil { t . Fatalf ( " " , err ) } if err := stack . Start ( ) ; err != nil { t . Fatalf ( " " , err ) } defer stack . Stop ( ) }
Tests that already constructed services can be retrieves by later ones.
Tests that already constructed services can be retrieves by later ones .
// Define a verifier that ensures a NoopA is before it and NoopB after // Register the collection of services // Start the protocol stack and ensure services are constructed in order