Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor the parent/dep uninstall scenarios
Signed-off-by: Vaughn Dice <vadice@microsoft.com>
- Loading branch information
Showing
3 changed files
with
99 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package porter | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPorter_HandleUninstallErrs(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
opts UninstallDeleteOptions | ||
err error | ||
wantOut string | ||
wantErr string | ||
}{ | ||
{ | ||
name: "no delete; no err", | ||
opts: UninstallDeleteOptions{}, | ||
}, { | ||
name: "no delete", | ||
opts: UninstallDeleteOptions{}, | ||
err: errors.New("an error was encountered"), | ||
wantErr: "an error was encountered", | ||
}, { | ||
name: "--delete; no --force-delete", | ||
opts: UninstallDeleteOptions{Delete: true}, | ||
err: errors.New("an error was encountered"), | ||
wantErr: fmt.Sprintf("2 errors occurred:\n\t* an error was encountered\n\t* %s\n\n", ErrUnsafeInstallationDeleteRetryForceDelete), | ||
}, { | ||
name: "--force-delete", | ||
opts: UninstallDeleteOptions{ForceDelete: true}, | ||
err: errors.New("an error was encountered"), | ||
wantOut: "ignoring the following errors as --force-delete is true:\n an error was encountered", | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
out := bytes.NewBufferString("") | ||
|
||
err := tc.opts.handleUninstallErrs(out, tc.err) | ||
if tc.wantErr != "" { | ||
require.EqualError(t, err, tc.wantErr) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
|
||
require.Equal(t, tc.wantOut, out.String()) | ||
}) | ||
} | ||
} |