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