| 1 | package limaembed |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | "testing/fstest" |
| 7 | ) |
| 8 | |
| 9 | func TestGuestAgentMatchesGuestAndCurrentBuild(t *testing.T) { |
| 10 | linuxArch := guestArch() |
| 11 | const darwinFile = "assets/Darwin/lima-guestagent.Darwin-aarch64.gz" |
| 12 | files := fstest.MapFS{ |
| 13 | "assets/lima-guestagent.Linux-" + linuxArch + ".gz": {Data: []byte("linux")}, |
| 14 | darwinFile: {Data: []byte("darwin")}, |
| 15 | } |
| 16 | dir := t.TempDir() |
| 17 | share, err := writeShare(dir, files) |
| 18 | if err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | for _, guest := range []struct{ os, arch, data string }{ |
| 22 | {"Linux", linuxArch, "linux"}, |
| 23 | {"Darwin", "aarch64", "darwin"}, |
| 24 | } { |
| 25 | path, err := share.GuestAgent(guest.os, guest.arch) |
| 26 | if err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | data, err := os.ReadFile(path) |
| 30 | if err != nil || string(data) != guest.data { |
| 31 | t.Fatalf("%s/%s: read %q, %v", guest.os, guest.arch, data, err) |
| 32 | } |
| 33 | } |
| 34 | if path, err := share.GuestAgent("Darwin", "x86_64"); err == nil { |
| 35 | t.Fatalf("used %s for an unbundled architecture", path) |
| 36 | } |
| 37 | |
| 38 | |
| 39 | delete(files, darwinFile) |
| 40 | share, err = writeShare(dir, files) |
| 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | if path, err := share.GuestAgent("Darwin", "aarch64"); err == nil { |
| 45 | t.Fatalf("used %s after the build stopped bundling it", path) |
| 46 | } |
| 47 | } |