Given the path where an extension should be installed and a manifest struct, creates a fake binary extension on disk
(installPath string, bm binManifest)
| 1572 | |
| 1573 | // Given the path where an extension should be installed and a manifest struct, creates a fake binary extension on disk |
| 1574 | func 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 | |
| 1607 | func stubExtensionUpdate(updatePath string) error { |
| 1608 | if _, err := os.Stat(updatePath); err == nil { |
no test coverage detected