MCPcopy
hub / github.com/cli/cli / stubBinaryExtension

Function stubBinaryExtension

pkg/cmd/extension/manager_test.go:1498–1529  ·  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

1496
1497// Given the path where an extension should be installed and a manifest struct, creates a fake binary extension on disk
1498func stubBinaryExtension(installPath string, bm binManifest) error {
1499 if err := os.MkdirAll(installPath, 0755); err != nil {
1500 return err
1501 }
1502 fakeBinaryPath := filepath.Join(installPath, filepath.Base(installPath))
1503 fb, err := os.OpenFile(fakeBinaryPath, os.O_CREATE, 0755)
1504 if err != nil {
1505 return err
1506 }
1507 err = fb.Close()
1508 if err != nil {
1509 return err
1510 }
1511
1512 bs, err := yaml.Marshal(bm)
1513 if err != nil {
1514 return fmt.Errorf("failed to serialize manifest: %w", err)
1515 }
1516
1517 manifestPath := filepath.Join(installPath, manifestName)
1518
1519 fm, err := os.OpenFile(manifestPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
1520 if err != nil {
1521 return fmt.Errorf("failed to open manifest for writing: %w", err)
1522 }
1523 _, err = fm.Write(bs)
1524 if err != nil {
1525 return fmt.Errorf("failed write manifest file: %w", err)
1526 }
1527
1528 return fm.Close()
1529}
1530
1531func stubExtensionUpdate(updatePath string) error {
1532 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