| 1 | package limaembed |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | |
| 10 | |
| 11 | func TestHostagentCopy(t *testing.T) { |
| 12 | upstream, err := os.ReadFile("../../third_party/lima/cmd/limactl/hostagent.go") |
| 13 | if err != nil { |
| 14 | t.Fatal(err) |
| 15 | } |
| 16 | ours, err := os.ReadFile("hostagent.go") |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | want := strings.Replace(string(upstream), "package main", "package limaembed", 1) |
| 21 | want = strings.Replace(want, "WrapArgsError(cobra.ExactArgs(1))", "cobra.ExactArgs(1)", 1) |
| 22 | want = strings.Replace(want, "signalCh := make(chan os.Signal, 1)", "signalCh := hostagentSignals", 1) |
| 23 | want = strings.Replace(want, "signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)", "signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)\n\tstopNotification, err := watchHostagentStop(socket)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer stopNotification()", 1) |
| 24 | |
| 25 | got := string(ours) |
| 26 | start := strings.Index(got, "// Copied from") |
| 27 | end := strings.Index(got, "package limaembed") |
| 28 | if start < 0 || end < start { |
| 29 | t.Fatal("hostagent.go lost its header") |
| 30 | } |
| 31 | got = got[:start] + got[end:] |
| 32 | if got != want { |
| 33 | t.Error("hostagent.go differs from third_party/lima/cmd/limactl/hostagent.go beyond its header: copy it again") |
| 34 | } |
| 35 | } |