MCPcopy
hub / github.com/cli/cli / Test_checkValidExtensionWithLocalExtension

Function Test_checkValidExtensionWithLocalExtension

pkg/cmd/extension/command_test.go:1070–1148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1068}
1069
1070func Test_checkValidExtensionWithLocalExtension(t *testing.T) {
1071 fakeRootCmd := &cobra.Command{}
1072 fakeRootCmd.AddCommand(&cobra.Command{Use: "help"})
1073 fakeRootCmd.AddCommand(&cobra.Command{Use: "auth"})
1074
1075 m := &extensions.ExtensionManagerMock{
1076 ListFunc: func() []extensions.Extension {
1077 return []extensions.Extension{
1078 &extensions.ExtensionMock{
1079 OwnerFunc: func() string { return "monalisa" },
1080 NameFunc: func() string { return "screensaver" },
1081 PathFunc: func() string { return "some/install/dir/gh-screensaver" },
1082 },
1083 &extensions.ExtensionMock{
1084 OwnerFunc: func() string { return "monalisa" },
1085 NameFunc: func() string { return "triage" },
1086 PathFunc: func() string { return "some/install/dir/gh-triage" },
1087 },
1088 }
1089 },
1090 }
1091
1092 type args struct {
1093 rootCmd *cobra.Command
1094 manager extensions.ExtensionManager
1095 dir string
1096 }
1097 tests := []struct {
1098 name string
1099 args args
1100 wantError string
1101 }{
1102 {
1103 name: "valid extension",
1104 args: args{
1105 rootCmd: fakeRootCmd,
1106 manager: m,
1107 dir: "some/install/dir/gh-hello",
1108 },
1109 },
1110 {
1111 name: "invalid extension name",
1112 args: args{
1113 rootCmd: fakeRootCmd,
1114 manager: m,
1115 dir: "some/install/dir/hello",
1116 },
1117 wantError: "extension name must start with `gh-`",
1118 },
1119 {
1120 name: "clashes with built-in command",
1121 args: args{
1122 rootCmd: fakeRootCmd,
1123 manager: m,
1124 dir: "some/install/dir/gh-auth",
1125 },
1126 wantError: "\"auth\" matches the name of a built-in command or alias",
1127 },

Callers

nothing calls this directly

Calls 3

checkValidExtensionFunction · 0.85
BaseMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected