Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "check target group health" #40

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func sleep(sec int, cfg Config) {
for {
select {
case t := <-ticker.C:
fmt.Fprintf(cfg.io.out, "\rRemain: %ds\033[K", int(finishAt.Sub(t).Seconds()))
fmt.Fprintf(cfg.io.out, "\rRemain: %ds ", int(finishAt.Sub(t).Seconds()))

case <-tickerStop:
fmt.Fprintln(cfg.io.out, "\a")
Expand Down Expand Up @@ -86,9 +86,6 @@ func execSwitch(targets map[TargetType]Targets, weight Weight, isForce bool, cfg
fmt.Fprintln(cfg.io.out, err.Error())
} else {
fmt.Fprintln(cfg.io.out, "switched!")
if err := target.checkHealth(weight, cfg); err != nil {
return err
}
}
}
}
Expand Down
32 changes: 0 additions & 32 deletions apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package tentez
import (
"bytes"
"context"
"math/rand"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
Expand Down Expand Up @@ -37,10 +35,6 @@ func (t targetMock) execSwitch(targetWeight Weight, isForce bool, cfg Config) er
return nil
}

func (t targetMock) checkHealth(targetWeight Weight, cfg Config) error {
return nil
}

func (t targetsMock) targetsSlice() []Target {
res := []Target{}
for _, v := range t {
Expand Down Expand Up @@ -109,32 +103,6 @@ func (m elbv2Mock) DescribeListeners(ctx context.Context, params *elbv2.Describe
func (m elbv2Mock) DescribeTargetGroups(ctx context.Context, params *elbv2.DescribeTargetGroupsInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeTargetGroupsOutput, error) {
return &elbv2.DescribeTargetGroupsOutput{}, m.DescribeListenersError
}
func (m elbv2Mock) DescribeTargetHealth(context.Context, *elbv2.DescribeTargetHealthInput, ...func(*elbv2.Options)) (*elbv2.DescribeTargetHealthOutput, error) {
rand.Seed(time.Now().UnixNano())
i := rand.Intn(2)
if i == 0 {
return &elbv2.DescribeTargetHealthOutput{
TargetHealthDescriptions: []elbv2Types.TargetHealthDescription{
{
TargetHealth: &elbv2Types.TargetHealth{
State: elbv2Types.TargetHealthStateEnumUnhealthy,
},
},
},
}, m.DescribeListenersError
} else {
return &elbv2.DescribeTargetHealthOutput{
TargetHealthDescriptions: []elbv2Types.TargetHealthDescription{
{
TargetHealth: &elbv2Types.TargetHealth{
State: elbv2Types.TargetHealthStateEnumHealthy,
},
},
},
}, m.DescribeListenersError

}
}

func TestExecSwitch(t *testing.T) {
cases := []struct {
Expand Down
4 changes: 0 additions & 4 deletions awsListener.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,3 @@ func (ls AwsListeners) targetsSlice() (targets []Target) {
}
return targets
}

func (l AwsListener) checkHealth(weight Weight, cfg Config) error {
return checkSwitchTargetGroupHealth(l.Switch, weight, cfg)
}
4 changes: 0 additions & 4 deletions awsListenerRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,3 @@ func (rs AwsListenerRules) targetsSlice() (targets []Target) {
}
return targets
}

func (r AwsListenerRule) checkHealth(weight Weight, cfg Config) error {
return checkSwitchTargetGroupHealth(r.Switch, weight, cfg)
}
42 changes: 0 additions & 42 deletions awsListenerRule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,45 +186,3 @@ func TestAwsListenerRules_fetchData(t *testing.T) {
}
}
}

func TestAwsListenerRule_checkHealth(t *testing.T) {
cases := []struct {
isError bool
awsListenerRule AwsListenerRule
weight Weight
elbv2Mock elbv2Mock
}{
{
isError: false,
awsListenerRule: AwsListenerRule{
Name: "success",
Target: "validTarget",
Switch: Switch{
Old: "oldTarget",
New: "newTarget",
},
},
weight: Weight{
Old: 50,
New: 50,
},
},
}

for _, c := range cases {
err := c.awsListenerRule.checkHealth(c.weight, Config{
client: Client{
elbv2: c.elbv2Mock,
},
io: IOStreams{
in: bytes.NewBufferString(""),
out: bytes.NewBufferString(""),
err: bytes.NewBufferString(""),
},
})

if c.isError != (err != nil) {
t.Errorf("%s: expect isError == %t, but got %v", c.awsListenerRule.Name, c.isError, err)
}
}
}
42 changes: 0 additions & 42 deletions awsListener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,45 +186,3 @@ func TestAwsListeners_fetchData(t *testing.T) {
}
}
}

func TestAwsListener_checkHealth(t *testing.T) {
cases := []struct {
isError bool
awsListener AwsListener
weight Weight
elbv2Mock elbv2Mock
}{
{
isError: false,
awsListener: AwsListener{
Name: "success",
Target: "validTarget",
Switch: Switch{
Old: "oldTarget",
New: "newTarget",
},
},
weight: Weight{
Old: 50,
New: 50,
},
},
}

for _, c := range cases {
err := c.awsListener.checkHealth(c.weight, Config{
client: Client{
elbv2: c.elbv2Mock,
},
io: IOStreams{
in: bytes.NewBufferString(""),
out: bytes.NewBufferString(""),
err: bytes.NewBufferString(""),
},
})

if c.isError != (err != nil) {
t.Errorf("%s: expect isError == %t, but got %v", c.awsListener.Name, c.isError, err)
}
}
}
77 changes: 0 additions & 77 deletions awsTargetGroup.go

This file was deleted.

1 change: 0 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type elbv2Client interface {
DescribeRules(ctx context.Context, params *elbv2.DescribeRulesInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeRulesOutput, error)
elbv2.DescribeListenersAPIClient
elbv2.DescribeTargetGroupsAPIClient
elbv2.DescribeTargetHealthAPIClient
}

type Client struct {
Expand Down
1 change: 0 additions & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tentez
type Target interface {
getName() string
execSwitch(weight Weight, isForce bool, cfg Config) error
checkHealth(weight Weight, cfg Config) error
}
type Targets interface {
targetsSlice() []Target
Expand Down