Skip to content

Commit

Permalink
Quick fix to resolve CLI isolation test failing (#6417)
Browse files Browse the repository at this point in the history
  • Loading branch information
timl3136 authored Oct 25, 2024
1 parent 2947ad3 commit 692319c
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions tools/cli/isolation_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
package cli

import (
"bytes"
"errors"
"flag"
"fmt"
"os"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -415,50 +413,29 @@ func TestAdminGetDomainIsolationGroups(t *testing.T) {

// Set up mocks for the current test case
tt.setupMocks(adminClient)
ioHandler := &testIOHandler{}

// Create mock app with clientFactoryMock, including any deps errors
app := NewCliApp(&clientFactoryMock{
serverAdminClient: adminClient,
})
}, WithIOHandler(ioHandler))

// Set up CLI context with flags
set := flag.NewFlagSet("test", 0)
set.String(FlagDomain, tt.flagDomain, "Domain flag")
set.String(FlagFormat, tt.flagFormat, "Format flag")
c := cli.NewContext(app, set, nil)

r, w, _ := os.Pipe()

// Save the original os.Stdout
origStdout := os.Stdout
// Defer restoring os.Stdout back to its original state
defer func() {
os.Stdout = origStdout
w.Close()
}()

// Redirect os.Stdout to the pipe
os.Stdout = w

// Call the function under test
err := AdminGetDomainIsolationGroups(c)

w.Close()
var buf bytes.Buffer
_, err2 := buf.ReadFrom(r)
if err2 != nil {
t.Fatalf("Failed to read from pipe: %v", err)
}
output := buf.String()

// Check the expected outcome
if tt.expectedError != "" {
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.expectedError)
} else {
assert.Contains(t, output, "zone-1")
assert.Contains(t, output, "zone-2")
assert.NoError(t, err)
assert.Contains(t, ioHandler.outputBytes.String(), "zone-1")
}
})
}
Expand Down

0 comments on commit 692319c

Please sign in to comment.