"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/extensions/manager_test.go" between
gh-cli-1.12.1.tar.gz and gh-cli-1.13.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

manager_test.go  (gh-cli-1.12.1):manager_test.go  (gh-cli-1.13.1)
skipping to change at line 47 skipping to change at line 47
args = append([]string{os.Args[0], "-test.run=TestHelperP rocess", "--", exe}, args...) args = append([]string{os.Args[0], "-test.run=TestHelperP rocess", "--", exe}, args...)
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
cmd.Env = []string{"GH_WANT_HELPER_PROCESS=1"} cmd.Env = []string{"GH_WANT_HELPER_PROCESS=1"}
return cmd return cmd
}, },
} }
} }
func TestManager_List(t *testing.T) { func TestManager_List(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
assert.NoError(t, stubExecutable(filepath.Join(tempDir, "extensions", "gh assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
-hello", "gh-hello"))) hello", "gh-hello")))
assert.NoError(t, stubExecutable(filepath.Join(tempDir, "extensions", "gh assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
-two", "gh-two"))) two", "gh-two")))
m := newTestManager(tempDir) m := newTestManager(tempDir)
exts := m.List() exts := m.List()
assert.Equal(t, 2, len(exts)) assert.Equal(t, 2, len(exts))
assert.Equal(t, "hello", exts[0].Name()) assert.Equal(t, "hello", exts[0].Name())
assert.Equal(t, "two", exts[1].Name()) assert.Equal(t, "two", exts[1].Name())
} }
func TestManager_Dispatch(t *testing.T) { func TestManager_Dispatch(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
extPath := filepath.Join(tempDir, "extensions", "gh-hello", "gh-hello") extPath := filepath.Join(tempDir, "extensions", "gh-hello", "gh-hello")
assert.NoError(t, stubExecutable(extPath)) assert.NoError(t, stubExtension(extPath))
m := newTestManager(tempDir) m := newTestManager(tempDir)
stdout := &bytes.Buffer{} stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{} stderr := &bytes.Buffer{}
found, err := m.Dispatch([]string{"hello", "one", "two"}, nil, stdout, st derr) found, err := m.Dispatch([]string{"hello", "one", "two"}, nil, stdout, st derr)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, found) assert.True(t, found)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
assert.Equal(t, fmt.Sprintf("[sh -c command \"$@\" -- %s one two] \n", extPath), stdout.String()) assert.Equal(t, fmt.Sprintf("[sh -c command \"$@\" -- %s one two] \n", extPath), stdout.String())
} else { } else {
assert.Equal(t, fmt.Sprintf("[%s one two]\n", extPath), stdout.St ring()) assert.Equal(t, fmt.Sprintf("[%s one two]\n", extPath), stdout.St ring())
} }
assert.Equal(t, "", stderr.String()) assert.Equal(t, "", stderr.String())
} }
func TestManager_Remove(t *testing.T) { func TestManager_Remove(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
assert.NoError(t, stubExecutable(filepath.Join(tempDir, "extensions", "gh assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
-hello", "gh-hello"))) hello", "gh-hello")))
assert.NoError(t, stubExecutable(filepath.Join(tempDir, "extensions", "gh assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
-two", "gh-two"))) two", "gh-two")))
m := newTestManager(tempDir) m := newTestManager(tempDir)
err := m.Remove("hello") err := m.Remove("hello")
assert.NoError(t, err) assert.NoError(t, err)
items, err := ioutil.ReadDir(filepath.Join(tempDir, "extensions")) items, err := ioutil.ReadDir(filepath.Join(tempDir, "extensions"))
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 1, len(items)) assert.Equal(t, 1, len(items))
assert.Equal(t, "gh-two", items[0].Name()) assert.Equal(t, "gh-two", items[0].Name())
} }
func TestManager_Upgrade(t *testing.T) { func TestManager_Upgrade_AllExtensions(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
assert.NoError(t, stubExecutable(filepath.Join(tempDir, "extensions", "gh assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
-hello", "gh-hello"))) hello", "gh-hello")))
assert.NoError(t, stubExecutable(filepath.Join(tempDir, "extensions", "gh assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
-two", "gh-two"))) two", "gh-two")))
assert.NoError(t, stubLocalExtension(filepath.Join(tempDir, "extensions",
"gh-local", "gh-local")))
m := newTestManager(tempDir) m := newTestManager(tempDir)
stdout := &bytes.Buffer{} stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{} stderr := &bytes.Buffer{}
err := m.Upgrade("", stdout, stderr) err := m.Upgrade("", stdout, stderr)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, heredoc.Docf( assert.Equal(t, heredoc.Docf(
` `
[hello]: [git -C %s --git-dir=%s pull --ff-only] [hello]: [git -C %s --git-dir=%s pull --ff-only]
[local]: local extensions can not be upgraded
[two]: [git -C %s --git-dir=%s pull --ff-only] [two]: [git -C %s --git-dir=%s pull --ff-only]
`, `,
filepath.Join(tempDir, "extensions", "gh-hello"), filepath.Join(tempDir, "extensions", "gh-hello"),
filepath.Join(tempDir, "extensions", "gh-hello", ".git"), filepath.Join(tempDir, "extensions", "gh-hello", ".git"),
filepath.Join(tempDir, "extensions", "gh-two"), filepath.Join(tempDir, "extensions", "gh-two"),
filepath.Join(tempDir, "extensions", "gh-two", ".git"), filepath.Join(tempDir, "extensions", "gh-two", ".git"),
), stdout.String()) ), stdout.String())
assert.Equal(t, "", stderr.String()) assert.Equal(t, "", stderr.String())
} }
func TestManager_Upgrade_RemoteExtension(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubExtension(filepath.Join(tempDir, "extensions", "gh-
remote", "gh-remote")))
m := newTestManager(tempDir)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
err := m.Upgrade("remote", stdout, stderr)
assert.NoError(t, err)
assert.Equal(t, heredoc.Docf(
`
[git -C %s --git-dir=%s pull --ff-only]
`,
filepath.Join(tempDir, "extensions", "gh-remote"),
filepath.Join(tempDir, "extensions", "gh-remote", ".git"),
), stdout.String())
assert.Equal(t, "", stderr.String())
}
func TestManager_Upgrade_LocalExtension(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, stubLocalExtension(filepath.Join(tempDir, "extensions",
"gh-local", "gh-local")))
m := newTestManager(tempDir)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
err := m.Upgrade("local", stdout, stderr)
assert.EqualError(t, err, "local extensions can not be upgraded")
assert.Equal(t, "", stdout.String())
assert.Equal(t, "", stderr.String())
}
func TestManager_Upgrade_NoExtensions(t *testing.T) {
tempDir := t.TempDir()
m := newTestManager(tempDir)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
err := m.Upgrade("", stdout, stderr)
assert.EqualError(t, err, "no extensions installed")
assert.Equal(t, "", stdout.String())
assert.Equal(t, "", stderr.String())
}
func TestManager_Install(t *testing.T) { func TestManager_Install(t *testing.T) {
tempDir := t.TempDir() tempDir := t.TempDir()
m := newTestManager(tempDir) m := newTestManager(tempDir)
stdout := &bytes.Buffer{} stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{} stderr := &bytes.Buffer{}
err := m.Install("https://github.com/owner/gh-some-ext.git", stdout, stde rr) err := m.Install("https://github.com/owner/gh-some-ext.git", stdout, stde rr)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("[git clone https://github.com/owner/gh-some- ext.git %s]\n", filepath.Join(tempDir, "extensions", "gh-some-ext")), stdout.Str ing()) assert.Equal(t, fmt.Sprintf("[git clone https://github.com/owner/gh-some- ext.git %s]\n", filepath.Join(tempDir, "extensions", "gh-some-ext")), stdout.Str ing())
assert.Equal(t, "", stderr.String()) assert.Equal(t, "", stderr.String())
} }
func stubExecutable(path string) error { func stubExtension(path string) error {
dir := filepath.Dir(path)
gitDir := filepath.Join(dir, ".git")
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
if err := os.Mkdir(gitDir, 0755); err != nil {
return err
}
f, err := os.OpenFile(path, os.O_CREATE, 0755)
if err != nil {
return err
}
return f.Close()
}
func stubLocalExtension(path string) error {
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return err return err
} }
f, err := os.OpenFile(path, os.O_CREATE, 0755) f, err := os.OpenFile(path, os.O_CREATE, 0755)
if err != nil { if err != nil {
return err return err
} }
return f.Close() return f.Close()
} }
 End of changes. 8 change blocks. 
15 lines changed or deleted 83 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)