| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | package launchd |
| 7 | |
| 8 | import ( |
| 9 | "strings" |
| 10 | "testing" |
| 11 | |
| 12 | "gotest.tools/v3/assert" |
| 13 | ) |
| 14 | |
| 15 | func TestGetPlistPath(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | Name string |
| 18 | InstanceName string |
| 19 | Expected string |
| 20 | }{ |
| 21 | { |
| 22 | Name: "darwin with docker instance name", |
| 23 | InstanceName: "docker", |
| 24 | Expected: "Library/LaunchAgents/io.lima-vm.autostart.docker.plist", |
| 25 | }, |
| 26 | } |
| 27 | for _, tt := range tests { |
| 28 | t.Run(tt.Name, func(t *testing.T) { |
| 29 | assert.Check(t, strings.HasSuffix(GetPlistPath(tt.InstanceName), tt.Expected)) |
| 30 | }) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestGetDaemonPlistPath(t *testing.T) { |
| 35 | tests := []struct { |
| 36 | Name string |
| 37 | InstanceName string |
| 38 | Expected string |
| 39 | }{ |
| 40 | { |
| 41 | Name: "k3s instance", |
| 42 | InstanceName: "k3s", |
| 43 | Expected: "/Library/LaunchDaemons/io.lima-vm.daemon.k3s.plist", |
| 44 | }, |
| 45 | { |
| 46 | Name: "default instance", |
| 47 | InstanceName: "default", |
| 48 | Expected: "/Library/LaunchDaemons/io.lima-vm.daemon.default.plist", |
| 49 | }, |
| 50 | } |
| 51 | for _, tt := range tests { |
| 52 | t.Run(tt.Name, func(t *testing.T) { |
| 53 | assert.Equal(t, GetDaemonPlistPath(tt.InstanceName), tt.Expected) |
| 54 | }) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestDaemonServiceNameFrom(t *testing.T) { |
| 59 | tests := []struct { |
| 60 | Name string |
| 61 | InstanceName string |
| 62 | Expected string |
| 63 | }{ |
| 64 | { |
| 65 | Name: "k3s instance", |
| 66 | InstanceName: "k3s", |
| 67 | Expected: "io.lima-vm.daemon.k3s", |
| 68 | }, |
| 69 | { |
| 70 | Name: "default instance", |
| 71 | InstanceName: "default", |
| 72 | Expected: "io.lima-vm.daemon.default", |
| 73 | }, |
| 74 | } |
| 75 | for _, tt := range tests { |
| 76 | t.Run(tt.Name, func(t *testing.T) { |
| 77 | assert.Equal(t, DaemonServiceNameFrom(tt.InstanceName), tt.Expected) |
| 78 | }) |
| 79 | } |
| 80 | } |