@@ -5,6 +5,10 @@ import (
55 "testing"
66
77 "github.com/stretchr/testify/assert"
8+ "github.com/stretchr/testify/mock"
9+
10+ "github.com/flyteorg/flyte/flyteidl/clients/go/admin/mocks"
11+ "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
812)
913
1014func TestInitializeClients (t * testing.T ) {
@@ -26,3 +30,61 @@ func TestInitializeClients(t *testing.T) {
2630 _ , ok = cs .asyncConnectorClients ["x" ]
2731 assert .True (t , ok )
2832}
33+
34+ func TestAgentForTaskTypesAlwaysOverwrite (t * testing.T ) {
35+ deploymentX := Deployment {Endpoint : "x" }
36+ deploymentY := Deployment {Endpoint : "y" }
37+ deploymentZ := Deployment {Endpoint : "z" }
38+ cfg := defaultConfig
39+ cfg .ConnectorDeployments = map [string ]* Deployment {
40+ "x" : & deploymentX ,
41+ "y" : & deploymentY ,
42+ "z" : & deploymentZ ,
43+ }
44+ cfg .ConnectorForTaskTypes = map [string ]string {
45+ "task1" : "x" , // we expect the "task1" task type should always route to deploymentX
46+ }
47+ ctx := context .Background ()
48+ err := SetConfig (& cfg )
49+ assert .NoError (t , err )
50+ cs := getConnectorClientSets (ctx )
51+
52+ // let's mock the "ListAgent" behaviour for 3 deployments
53+ // they both have SupportedTaskTypes "task1"
54+ mockClientForDeploymentX := mocks .NewAgentMetadataServiceClient (t )
55+ mockClientForDeploymentY := mocks .NewAgentMetadataServiceClient (t )
56+ mockClientForDeploymentZ := mocks .NewAgentMetadataServiceClient (t )
57+ mockClientForDeploymentX .On ("ListAgents" , mock .Anything , mock .Anything ).Return (& admin.ListAgentsResponse {
58+ Agents : []* admin.Agent {
59+ {
60+ Name : "connector1" ,
61+ SupportedTaskTypes : []string {"task1" },
62+ },
63+ },
64+ }, nil )
65+ mockClientForDeploymentY .On ("ListAgents" , mock .Anything , mock .Anything ).Return (& admin.ListAgentsResponse {
66+ Agents : []* admin.Agent {
67+ {
68+ Name : "connector2" ,
69+ SupportedTaskTypes : []string {"task1" },
70+ },
71+ },
72+ }, nil )
73+ mockClientForDeploymentZ .On ("ListAgents" , mock .Anything , mock .Anything ).Return (& admin.ListAgentsResponse {
74+ Agents : []* admin.Agent {
75+ {
76+ Name : "connector3" ,
77+ SupportedTaskTypes : []string {"task1" },
78+ },
79+ },
80+ }, nil )
81+ cs .connectorMetadataClients [deploymentX .Endpoint ] = mockClientForDeploymentX
82+ cs .connectorMetadataClients [deploymentY .Endpoint ] = mockClientForDeploymentY
83+ cs .connectorMetadataClients [deploymentZ .Endpoint ] = mockClientForDeploymentZ
84+ // while auto-discovery execute in getAgentRegistry function, the deployment of task1 will be amended to deploymentZ
85+ // but the always-overwrite policy will overwrite deployment of task1 back to deploymentX according to cfg.AgentForTaskTypes
86+ registry := getConnectorRegistry (ctx , cs )
87+ finalDeployment := registry ["task1" ][defaultTaskTypeVersion ].ConnectorDeployment
88+ expectedDeployment := & deploymentX
89+ assert .Equal (t , finalDeployment , expectedDeployment )
90+ }
0 commit comments