@ -529,7 +529,7 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
t . Run ( tt . desc , func ( t * testing . T ) {
// check the service registration
t . Run ( tt . srv . ID , func ( t * testing . T ) {
err := a . A ddServiceFromSource( tt . srv , tt . chkTypes , false , "" , ConfigSourceLocal )
err := a . a ddServiceFromSource( tt . srv , tt . chkTypes , false , "" , ConfigSourceLocal )
if err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -572,6 +572,20 @@ func testAgent_AddService(t *testing.T, extraHCL string) {
}
}
// addServiceFromSource is a test helper that exists to maintain an old function
// signature that was used in many tests.
// Deprecated: use AddService
func ( a * Agent ) addServiceFromSource ( service * structs . NodeService , chkTypes [ ] * structs . CheckType , persist bool , token string , source configSource ) error {
return a . AddService ( AddServiceRequest {
Service : service ,
chkTypes : chkTypes ,
persist : persist ,
token : token ,
replaceExistingChecks : false ,
Source : source ,
} )
}
func TestAgent_AddServices_AliasUpdateCheckNotReverted ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
@ -638,7 +652,7 @@ func testAgent_AddServices_AliasUpdateCheckNotReverted(t *testing.T, extraHCL st
chkTypes , err := service . CheckTypes ( )
require . NoError ( t , err )
require . NoError ( t , a . A ddServiceFromSource( ns , chkTypes , false , service . Token , ConfigSourceLocal ) )
require . NoError ( t , a . a ddServiceFromSource( ns , chkTypes , false , service . Token , ConfigSourceLocal ) )
}
retry . Run ( t , func ( r * retry . R ) {
@ -665,7 +679,7 @@ func test_createAlias(t *testing.T, agent *TestAgent, chk *structs.CheckType, ex
if chk . CheckID == "" {
chk . CheckID = types . CheckID ( fmt . Sprintf ( "check-%d" , serviceNum ) )
}
err := agent . A ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceLocal )
err := agent . a ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceLocal )
assert . NoError ( t , err )
return func ( r * retry . R ) {
t . Helper ( )
@ -712,7 +726,7 @@ func TestAgent_CheckAliasRPC(t *testing.T) {
// We ensure to not block and update Agent's index
srv . Tags = [ ] string { fmt . Sprintf ( "tag-%s" , time . Now ( ) ) }
assert . NoError ( t , a . waitForUp ( ) )
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceLocal )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceLocal )
assert . NoError ( t , err )
}
shutdownAgent := func ( ) {
@ -727,7 +741,7 @@ func TestAgent_CheckAliasRPC(t *testing.T) {
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
assert . NoError ( t , a . waitForUp ( ) )
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceLocal )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceLocal )
assert . NoError ( t , err )
retry . Run ( t , func ( r * retry . R ) {
@ -832,12 +846,12 @@ func testAgent_AddServiceNoExec(t *testing.T, extraHCL string) {
Interval : 15 * time . Second ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceLocal )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceLocal )
if err == nil || ! strings . Contains ( err . Error ( ) , "Scripts are disabled on this agent" ) {
t . Fatalf ( "err: %v" , err )
}
err = a . A ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceRemote )
err = a . a ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceRemote )
if err == nil || ! strings . Contains ( err . Error ( ) , "Scripts are disabled on this agent" ) {
t . Fatalf ( "err: %v" , err )
}
@ -879,7 +893,7 @@ func testAgent_AddServiceNoRemoteExec(t *testing.T, extraHCL string) {
Interval : 15 * time . Second ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceRemote )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { chk } , false , "" , ConfigSourceRemote )
if err == nil || ! strings . Contains ( err . Error ( ) , "Scripts are disabled on this agent" ) {
t . Fatalf ( "err: %v" , err )
}
@ -932,7 +946,7 @@ func TestCacheRateLimit(t *testing.T) {
Address : fmt . Sprintf ( "10.0.1.%d" , i % 255 ) ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
require . Nil ( t , err )
}
@ -1007,7 +1021,7 @@ func TestAddServiceIPv4TaggedDefault(t *testing.T) {
Address : "10.0.1.2" ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
require . Nil ( t , err )
ns := a . State . Service ( structs . NewServiceID ( "my_service_id" , nil ) )
@ -1040,7 +1054,7 @@ func TestAddServiceIPv6TaggedDefault(t *testing.T) {
Address : "::5" ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
require . Nil ( t , err )
ns := a . State . Service ( structs . NewServiceID ( "my_service_id" , nil ) )
@ -1079,7 +1093,7 @@ func TestAddServiceIPv4TaggedSet(t *testing.T) {
} ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
require . Nil ( t , err )
ns := a . State . Service ( structs . NewServiceID ( "my_service_id" , nil ) )
@ -1118,7 +1132,7 @@ func TestAddServiceIPv6TaggedSet(t *testing.T) {
} ,
}
err := a . A ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
err := a . a ddServiceFromSource( srv , [ ] * structs . CheckType { } , false , "" , ConfigSourceRemote )
require . Nil ( t , err )
ns := a . State . Service ( structs . NewServiceID ( "my_service_id" , nil ) )
@ -1173,7 +1187,7 @@ func testAgent_RemoveService(t *testing.T, extraHCL string) {
}
chkTypes := [ ] * structs . CheckType { { TTL : time . Minute } }
if err := a . A ddServiceFromSource( srv , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( srv , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -1208,7 +1222,7 @@ func testAgent_RemoveService(t *testing.T, extraHCL string) {
{ TTL : time . Minute } ,
{ TTL : 30 * time . Second } ,
}
if err := a . A ddServiceFromSource( srv , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( srv , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -1222,7 +1236,7 @@ func testAgent_RemoveService(t *testing.T, extraHCL string) {
{ TTL : time . Minute } ,
{ TTL : 30 * time . Second } ,
}
if err := a . A ddServiceFromSource( srv , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( srv , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -1294,7 +1308,7 @@ func testAgent_RemoveServiceRemovesAllChecks(t *testing.T, extraHCL string) {
}
// register service with chk1
if err := a . A ddServiceFromSource( svc , [ ] * structs . CheckType { chk1 } , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , [ ] * structs . CheckType { chk1 } , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatal ( "Failed to register service" , err )
}
@ -1302,7 +1316,7 @@ func testAgent_RemoveServiceRemovesAllChecks(t *testing.T, extraHCL string) {
requireCheckExists ( t , a , "chk1" )
// update the service with chk2
if err := a . A ddServiceFromSource( svc , [ ] * structs . CheckType { chk2 } , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , [ ] * structs . CheckType { chk2 } , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatal ( "Failed to update service" , err )
}
@ -1359,7 +1373,7 @@ func verifyIndexChurn(t *testing.T, tags []string) {
Tags : tags ,
Weights : weights ,
}
if err := a . A ddServiceFromSource( svc , nil , true , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , true , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -1767,7 +1781,7 @@ func TestAgent_RestoreServiceWithAliasCheck(t *testing.T) {
registerServicesAndChecks := func ( t * testing . T , a * TestAgent ) {
// add one persistent service with a simple check
require . NoError ( t , a . A ddServiceFromSource(
require . NoError ( t , a . a ddServiceFromSource(
& structs . NodeService {
ID : "ping" ,
Service : "ping" ,
@ -1786,7 +1800,7 @@ func TestAgent_RestoreServiceWithAliasCheck(t *testing.T) {
// add one persistent sidecar service with an alias check in the manner
// of how sidecar_service would add it
require . NoError ( t , a . A ddServiceFromSource(
require . NoError ( t , a . a ddServiceFromSource(
& structs . NodeService {
ID : "ping-sidecar-proxy" ,
Service : "ping-sidecar-proxy" ,
@ -2276,7 +2290,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
file := filepath . Join ( a . Config . DataDir , servicesDir , stringHash ( svc . ID ) )
// Check is not persisted unless requested
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
if _ , err := os . Stat ( file ) ; err == nil {
@ -2284,7 +2298,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
}
// Persists to file if requested
if err := a . A ddServiceFromSource( svc , nil , true , "mytoken" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , true , "mytoken" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
if _ , err := os . Stat ( file ) ; err != nil {
@ -2308,7 +2322,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
// Updates service definition on disk
svc . Port = 8001
if err := a . A ddServiceFromSource( svc , nil , true , "mytoken" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , true , "mytoken" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
expected , err = json . Marshal ( persistedService {
@ -2431,7 +2445,7 @@ func testAgent_PurgeService(t *testing.T, extraHCL string) {
}
file := filepath . Join ( a . Config . DataDir , servicesDir , stringHash ( svc . ID ) )
if err := a . A ddServiceFromSource( svc , nil , true , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , true , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
// Exists
@ -2448,7 +2462,7 @@ func testAgent_PurgeService(t *testing.T, extraHCL string) {
}
// Re-add the service
if err := a . A ddServiceFromSource( svc , nil , true , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , true , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -2494,7 +2508,7 @@ func testAgent_PurgeServiceOnDuplicate(t *testing.T, extraHCL string) {
}
// First persist the service
require . NoError ( t , a . A ddServiceFromSource( svc1 , nil , true , "" , ConfigSourceLocal ) )
require . NoError ( t , a . a ddServiceFromSource( svc1 , nil , true , "" , ConfigSourceLocal ) )
a . Shutdown ( )
// Try bringing the agent back up with the service already
@ -2742,9 +2756,9 @@ func TestAgent_DeregisterPersistedSidecarAfterRestart(t *testing.T) {
require . NoError ( t , err )
// First persist the check
err = a . A ddServiceFromSource( srv , nil , true , "" , ConfigSourceLocal )
err = a . a ddServiceFromSource( srv , nil , true , "" , ConfigSourceLocal )
require . NoError ( t , err )
err = a . A ddServiceFromSource( connectSrv , nil , true , "" , ConfigSourceLocal )
err = a . a ddServiceFromSource( connectSrv , nil , true , "" , ConfigSourceLocal )
require . NoError ( t , err )
// check both services were registered
@ -2814,7 +2828,7 @@ func TestAgent_unloadChecks(t *testing.T) {
Tags : [ ] string { "foo" } ,
Port : 8000 ,
}
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -3093,7 +3107,7 @@ func testAgent_unloadServices(t *testing.T, extraHCL string) {
}
// Register the service
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -3125,7 +3139,7 @@ func TestAgent_Service_MaintenanceMode(t *testing.T) {
}
// Register the service
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -3206,7 +3220,7 @@ func TestAgent_Service_Reap(t *testing.T) {
}
// Register the service.
if err := a . A ddServiceFromSource( svc , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -3263,7 +3277,7 @@ func TestAgent_Service_NoReap(t *testing.T) {
}
// Register the service.
if err := a . A ddServiceFromSource( svc , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , chkTypes , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -3310,7 +3324,7 @@ func testAgent_AddService_restoresSnapshot(t *testing.T, extraHCL string) {
Tags : [ ] string { "foo" } ,
Port : 8000 ,
}
require . NoError ( t , a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) )
require . NoError ( t , a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) )
// Register a check
check1 := & structs . HealthCheck {
@ -3325,7 +3339,7 @@ func testAgent_AddService_restoresSnapshot(t *testing.T, extraHCL string) {
// Re-registering the service preserves the state of the check
chkTypes := [ ] * structs . CheckType { { TTL : 30 * time . Second } }
require . NoError ( t , a . A ddServiceFromSource( svc , chkTypes , false , "" , ConfigSourceLocal ) )
require . NoError ( t , a . a ddServiceFromSource( svc , chkTypes , false , "" , ConfigSourceLocal ) )
check := requireCheckExists ( t , a , "service:redis" )
require . Equal ( t , api . HealthPassing , check . Status )
}
@ -3346,7 +3360,7 @@ func TestAgent_AddCheck_restoresSnapshot(t *testing.T) {
Tags : [ ] string { "foo" } ,
Port : 8000 ,
}
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -3431,7 +3445,7 @@ func TestAgent_checkStateSnapshot(t *testing.T) {
Tags : [ ] string { "foo" } ,
Port : 8000 ,
}
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "err: %v" , err )
}
@ -4250,7 +4264,7 @@ func TestAgent_RerouteExistingHTTPChecks(t *testing.T) {
TLSSkipVerify : true ,
} ,
}
if err := a . A ddServiceFromSource( svc , chks , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , chks , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "failed to add svc: %v" , err )
}
@ -4273,7 +4287,7 @@ func TestAgent_RerouteExistingHTTPChecks(t *testing.T) {
} ,
} ,
}
if err := a . A ddServiceFromSource( proxy , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( proxy , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "failed to add svc: %v" , err )
}
@ -4326,7 +4340,7 @@ func TestAgent_RerouteExistingHTTPChecks(t *testing.T) {
} ,
} ,
}
if err := a . A ddServiceFromSource( proxy , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( proxy , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "failed to add svc: %v" , err )
}
@ -4369,7 +4383,7 @@ func TestAgent_RerouteNewHTTPChecks(t *testing.T) {
Address : "localhost" ,
Port : 8080 ,
}
if err := a . A ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( svc , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "failed to add svc: %v" , err )
}
@ -4391,7 +4405,7 @@ func TestAgent_RerouteNewHTTPChecks(t *testing.T) {
} ,
} ,
}
if err := a . A ddServiceFromSource( proxy , nil , false , "" , ConfigSourceLocal ) ; err != nil {
if err := a . a ddServiceFromSource( proxy , nil , false , "" , ConfigSourceLocal ) ; err != nil {
t . Fatalf ( "failed to add svc: %v" , err )
}