Skip to content

Commit

Permalink
fix: refactor and make the code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Sep 11, 2024
1 parent 6d6d08a commit 60a5a8e
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions xds/internal/balancer/clusterimpl/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ func (s) TestUpdateLRSServer(t *testing.T) {
// Test verifies that child policies was updated on receipt of
// configuration update.
func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName)
xdsC := fakeclient.NewClient()

builder := balancer.Get(Name)
Expand All @@ -864,19 +863,13 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
stub.Register(childPolicyName1, stub.BalancerFuncs{
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {

Check failure on line 864 in xds/internal/balancer/clusterimpl/balancer_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

parameter 'bd' seems to be unused, consider removing or renaming it as _ https://revive.run/r#unused-parameter

Check failure on line 864 in xds/internal/balancer/clusterimpl/balancer_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

parameter 'ccs' seems to be unused, consider removing or renaming it as _ https://revive.run/r#unused-parameter
updatedChildPolicy = childPolicyName1
bd.ClientConn.UpdateState(balancer.State{
Picker: base.NewErrPicker(errors.New("dummy error picker")),
})
return nil
},
})

stub.Register(childPolicyName2, stub.BalancerFuncs{
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {

Check failure on line 871 in xds/internal/balancer/clusterimpl/balancer_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

parameter 'bd' seems to be unused, consider removing or renaming it as _ https://revive.run/r#unused-parameter

Check failure on line 871 in xds/internal/balancer/clusterimpl/balancer_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

parameter 'ccs' seems to be unused, consider removing or renaming it as _ https://revive.run/r#unused-parameter
updatedChildPolicy = childPolicyName2
bd.ClientConn.UpdateState(balancer.State{
Picker: base.NewErrPicker(errors.New("dummy error picker")),
})
return nil
},
})
Expand All @@ -885,8 +878,7 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
if err := b.UpdateClientConnState(balancer.ClientConnState{
ResolverState: xdsclient.SetClient(resolver.State{Addresses: testBackendAddrs}, xdsC),
BalancerConfig: &LBConfig{
Cluster: testClusterName,
EDSServiceName: testServiceName,
Cluster: testClusterName,
ChildPolicy: &internalserviceconfig.BalancerConfig{
Name: childPolicyName1,
},
Expand All @@ -903,8 +895,7 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
if err := b.UpdateClientConnState(balancer.ClientConnState{
ResolverState: xdsclient.SetClient(resolver.State{Addresses: testBackendAddrs}, xdsC),
BalancerConfig: &LBConfig{
Cluster: testClusterName,
EDSServiceName: testServiceName,
Cluster: testClusterName,
ChildPolicy: &internalserviceconfig.BalancerConfig{
Name: childPolicyName2,
},
Expand All @@ -921,7 +912,6 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
// Test verifies that config update fails if child policy config
// failed to parse.
func (s) TestFailedToParseChildPolicyConfig(t *testing.T) {
defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName)
xdsC := fakeclient.NewClient()

builder := balancer.Get(Name)
Expand All @@ -933,12 +923,6 @@ func (s) TestFailedToParseChildPolicyConfig(t *testing.T) {
const parseConfigError = "failed to parse config"
const childPolicyName = "stubBalancer-FailedToParseChildPolicyConfig"
stub.Register(childPolicyName, stub.BalancerFuncs{
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
bd.ClientConn.UpdateState(balancer.State{
Picker: base.NewErrPicker(errors.New("dummy error picker")),
})
return nil
},
ParseConfig: func(lbCfg json.RawMessage) (serviceconfig.LoadBalancingConfig, error) {

Check failure on line 926 in xds/internal/balancer/clusterimpl/balancer_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

parameter 'lbCfg' seems to be unused, consider removing or renaming it as _ https://revive.run/r#unused-parameter
return nil, errors.New(parseConfigError)
},
Expand All @@ -947,16 +931,15 @@ func (s) TestFailedToParseChildPolicyConfig(t *testing.T) {
err := b.UpdateClientConnState(balancer.ClientConnState{
ResolverState: xdsclient.SetClient(resolver.State{Addresses: testBackendAddrs}, xdsC),
BalancerConfig: &LBConfig{
Cluster: testClusterName,
EDSServiceName: testServiceName,
Cluster: testClusterName,
ChildPolicy: &internalserviceconfig.BalancerConfig{
Name: childPolicyName,
},
},
})

if err == nil || !strings.Contains(err.Error(), parseConfigError) {
t.Errorf("Got error: %v, want error: parsed config to fail.", err)
t.Fatalf("Got error: %v, want error: %s", err, parseConfigError)
}
}

Expand Down

0 comments on commit 60a5a8e

Please sign in to comment.