MCPcopy Create free account
hub / github.com/cli/cli / stubBinaryExtension

Function stubBinaryExtension

pkg/cmd/extension/manager_test.go:1574–1605  ·  view source on GitHub ↗

Given the path where an extension should be installed and a manifest struct, creates a fake binary extension on disk

(installPath string, bm binManifest)

Source from the content-addressed store, hash-verified

1572
1573// Given the path where an extension should be installed and a manifest struct, creates a fake binary extension on disk
1574func stubBinaryExtension(installPath string, bm binManifest) error {
1575 if err := os.MkdirAll(installPath, 0755); err != nil {
1576 return err
1577 }
1578 fakeBinaryPath := filepath.Join(installPath, filepath.Base(installPath))
1579 fb, err := os.OpenFile(fakeBinaryPath, os.O_CREATE, 0755)
1580 if err != nil {
1581 return err
1582 }
1583 err = fb.Close()
1584 if err != nil {
1585 return err
1586 }
1587
1588 bs, err := yaml.Marshal(bm)
1589 if err != nil {
1590 return fmt.Errorf("failed to serialize manifest: %w", err)
1591 }
1592
1593 manifestPath := filepath.Join(installPath, manifestName)
1594
1595 fm, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
1596 if err != nil {
1597 return fmt.Errorf("failed to open manifest for writing: %w", err)
1598 }
1599 _, err = fm.Write(bs)
1600 if err != nil {
1601 return fmt.Errorf("failed write manifest file: %w", err)
1602 }
1603
1604 return fm.Close()
1605}
1606
1607func stubExtensionUpdate(updatePath string) error {
1608 if _, err := os.Stat(updatePath); err == nil {

Calls 5

JoinMethod · 0.80
BaseMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected