Skip to content

Commit

Permalink
Code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lkysow committed Mar 18, 2020
1 parent c0e1b9b commit fcc6ed2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions subcommand/load-balancer-address/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestRun_UnableToWriteToFile(t *testing.T) {
}

// Test running with different permutations of ingress.
func TestRun_IngressPermutations(t *testing.T) {
func TestRun_LoadBalancerIngressPermutations(t *testing.T) {
t.Parallel()
require := require.New(t)

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestRun_IngressPermutations(t *testing.T) {
}
tmpDir, err := ioutil.TempDir("", "")
require.NoError(err)
defer os.Remove(tmpDir)
defer os.RemoveAll(tmpDir)
outputFile := filepath.Join(tmpDir, "address.txt")

responseCode := cmd.Run([]string{
Expand Down Expand Up @@ -171,30 +171,26 @@ func TestRun_FileWrittenAfterRetry(t *testing.T) {
// with the UpdateIP address. NOTE: the retry duration for this
// test is set to 10ms.
UpdateDelay time.Duration
// UpdateIP is the IP we update the service with after UpdateDelay.
UpdateIP string
}{
"initial service exists": {
InitialService: true,
UpdateDelay: 50 * time.Millisecond,
UpdateIP: "1.2.3.4",
},
"initial service does not exist, immediate update": {
InitialService: false,
UpdateDelay: 0,
UpdateIP: "1.2.3.4",
},
"initial service does not exist, 50ms delay": {
InitialService: false,
UpdateDelay: 50 * time.Millisecond,
UpdateIP: "1.2.3.4",
},
}

for name, c := range cases {
t.Run(name, func(t *testing.T) {
k8sNS := "default"
svcName := "service-name"
ip := "1.2.3.4"
k8s := fake.NewSimpleClientset()

if c.InitialService {
Expand All @@ -209,7 +205,7 @@ func TestRun_FileWrittenAfterRetry(t *testing.T) {
// Create/update the service after delay.
go func() {
time.Sleep(c.UpdateDelay)
svc := kubeSvc(svcName, c.UpdateIP, "")
svc := kubeSvc(svcName, ip, "")
var err error
if c.InitialService {
_, err = k8s.CoreV1().Services(k8sNS).Update(svc)
Expand All @@ -228,7 +224,7 @@ func TestRun_FileWrittenAfterRetry(t *testing.T) {
}
tmpDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.Remove(tmpDir)
defer os.RemoveAll(tmpDir)
outputFile := filepath.Join(tmpDir, "address.txt")

responseCode := cmd.Run([]string{
Expand All @@ -239,7 +235,7 @@ func TestRun_FileWrittenAfterRetry(t *testing.T) {
require.Equal(t, 0, responseCode, ui.ErrorWriter.String())
actAddressBytes, err := ioutil.ReadFile(outputFile)
require.NoError(t, err)
require.Equal(t, c.UpdateIP, string(actAddressBytes))
require.Equal(t, ip, string(actAddressBytes))
})
}
}
Expand Down

0 comments on commit fcc6ed2

Please sign in to comment.