|
| 1 | +package launch |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/itchio/butler/butlerd" |
| 10 | + "github.com/itchio/butler/manager" |
| 11 | + "github.com/itchio/dash" |
| 12 | + "github.com/itchio/headway/state" |
| 13 | + "github.com/itchio/hush/manifest" |
| 14 | + "github.com/itchio/ox" |
| 15 | +) |
| 16 | + |
| 17 | +func TestGetTargetsForHost_NativeAllManifestActionsFail(t *testing.T) { |
| 18 | + t.Parallel() |
| 19 | + |
| 20 | + installFolder := t.TempDir() |
| 21 | + runtime := ox.Runtime{Platform: ox.PlatformLinux, Is64: true} |
| 22 | + |
| 23 | + rc := &butlerd.RequestContext{Consumer: &state.Consumer{}} |
| 24 | + info := withInstallFolderInfo{ |
| 25 | + installFolder: installFolder, |
| 26 | + runtime: runtime, |
| 27 | + } |
| 28 | + host := manager.Host{Runtime: runtime} |
| 29 | + |
| 30 | + appManifest := &manifest.Manifest{ |
| 31 | + Actions: manifest.Actions{ |
| 32 | + { |
| 33 | + Name: "Default", |
| 34 | + Path: "Missing{{EXT}}", |
| 35 | + }, |
| 36 | + }, |
| 37 | + } |
| 38 | + |
| 39 | + _, err := getTargetsForHost(rc, nil, appManifest, &dash.Verdict{}, info, host) |
| 40 | + if err == nil { |
| 41 | + t.Fatalf("expected error when all native manifest actions fail") |
| 42 | + } |
| 43 | + if !strings.Contains(err.Error(), "failed to resolve 1/1 manifest actions for native host") { |
| 44 | + t.Fatalf("expected native manifest failure error, got: %v", err) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func TestGetTargetsForHost_NonNativeAllManifestActionsFail(t *testing.T) { |
| 49 | + t.Parallel() |
| 50 | + |
| 51 | + installFolder := t.TempDir() |
| 52 | + nativeRuntime := ox.Runtime{Platform: ox.PlatformLinux, Is64: true} |
| 53 | + wineRuntime := ox.Runtime{Platform: ox.PlatformWindows, Is64: false} |
| 54 | + |
| 55 | + rc := &butlerd.RequestContext{Consumer: &state.Consumer{}} |
| 56 | + info := withInstallFolderInfo{ |
| 57 | + installFolder: installFolder, |
| 58 | + runtime: nativeRuntime, |
| 59 | + } |
| 60 | + host := manager.Host{ |
| 61 | + Runtime: wineRuntime, |
| 62 | + Wrapper: &manager.Wrapper{ |
| 63 | + WrapperBinary: "wine", |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + appManifest := &manifest.Manifest{ |
| 68 | + Actions: manifest.Actions{ |
| 69 | + { |
| 70 | + Name: "Default", |
| 71 | + Path: "Missing{{EXT}}", |
| 72 | + }, |
| 73 | + }, |
| 74 | + } |
| 75 | + |
| 76 | + targets, err := getTargetsForHost(rc, nil, appManifest, &dash.Verdict{}, info, host) |
| 77 | + if err != nil { |
| 78 | + t.Fatalf("expected no error for non-native host when all manifest actions fail, got: %v", err) |
| 79 | + } |
| 80 | + if len(targets) != 0 { |
| 81 | + t.Fatalf("expected no targets from empty fallback verdict, got %d", len(targets)) |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +func TestGetTargetsForHost_NativePartialManifestResolution(t *testing.T) { |
| 86 | + t.Parallel() |
| 87 | + |
| 88 | + installFolder := t.TempDir() |
| 89 | + runtime := ox.Runtime{Platform: ox.PlatformLinux, Is64: true} |
| 90 | + |
| 91 | + rc := &butlerd.RequestContext{Consumer: &state.Consumer{}} |
| 92 | + info := withInstallFolderInfo{ |
| 93 | + installFolder: installFolder, |
| 94 | + runtime: runtime, |
| 95 | + } |
| 96 | + host := manager.Host{Runtime: runtime} |
| 97 | + |
| 98 | + validActionDir := filepath.Join(installFolder, "Sample Evil App") |
| 99 | + if err := os.MkdirAll(validActionDir, 0o755); err != nil { |
| 100 | + t.Fatalf("creating valid action dir: %v", err) |
| 101 | + } |
| 102 | + |
| 103 | + appManifest := &manifest.Manifest{ |
| 104 | + Actions: manifest.Actions{ |
| 105 | + { |
| 106 | + Name: "Valid", |
| 107 | + Path: "Sample Evil App{{EXT}}", |
| 108 | + }, |
| 109 | + { |
| 110 | + Name: "Missing", |
| 111 | + Path: "Missing{{EXT}}", |
| 112 | + }, |
| 113 | + }, |
| 114 | + } |
| 115 | + |
| 116 | + targets, err := getTargetsForHost(rc, nil, appManifest, &dash.Verdict{}, info, host) |
| 117 | + if err != nil { |
| 118 | + t.Fatalf("expected no error when at least one native action resolves, got: %v", err) |
| 119 | + } |
| 120 | + if len(targets) == 0 { |
| 121 | + t.Fatalf("expected at least one resolved target") |
| 122 | + } |
| 123 | +} |
0 commit comments