5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 07:29:56 +08:00
wails/v3/internal/commands/tool_package_test.go
Atterpac 9173537ce5
[V3-Linux] Support for deb,rpm,arch linux packager packaging (#3909)
* Support for linux deb,rpm,arch linux packager packaging

* remove optional tasks from linux:package task

CHANGELOG.md

* Update Taskfile.linux.yml

* Integrated nfpm into CLI.
Fixed task update.

* package tool fixes and add bundle name field

empty name guard

* add linux depdencies

* Add some docs

* Fixed tests. Updated task to latest.

* Update v3/internal/commands/tool_package.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Remove doctor references to nfpm

---------

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-11-30 13:31:56 +11:00

144 lines
3.3 KiB
Go

package commands
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/wailsapp/wails/v3/internal/flags"
)
func TestToolPackage(t *testing.T) {
tests := []struct {
name string
setup func() (*flags.ToolPackage, func())
wantErr bool
errMsg string
}{
{
name: "should fail with invalid format",
setup: func() (*flags.ToolPackage, func()) {
return &flags.ToolPackage{
Format: "invalid",
ConfigPath: "config.yaml",
ExecutableName: "myapp",
}, func() {}
},
wantErr: true,
errMsg: "unsupported package format",
},
{
name: "should fail with missing config file",
setup: func() (*flags.ToolPackage, func()) {
return &flags.ToolPackage{
Format: "deb",
ConfigPath: "nonexistent.yaml",
ExecutableName: "myapp",
}, func() {}
},
wantErr: true,
errMsg: "config file not found",
},
{
name: "should handle case-insensitive format (DEB)",
setup: func() (*flags.ToolPackage, func()) {
// Create a temporary config file
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yaml")
err := os.WriteFile(configPath, []byte("name: test"), 0644)
if err != nil {
t.Fatal(err)
}
// Create bin directory
err = os.MkdirAll(filepath.Join(dir, "bin"), 0755)
if err != nil {
t.Fatal(err)
}
return &flags.ToolPackage{
Format: "DEB",
ConfigPath: configPath,
ExecutableName: "myapp",
}, func() {
os.RemoveAll(filepath.Join(dir, "bin"))
}
},
wantErr: false,
},
{
name: "should handle case-insensitive format (RPM)",
setup: func() (*flags.ToolPackage, func()) {
// Create a temporary config file
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yaml")
err := os.WriteFile(configPath, []byte("name: test"), 0644)
if err != nil {
t.Fatal(err)
}
// Create bin directory
err = os.MkdirAll(filepath.Join(dir, "bin"), 0755)
if err != nil {
t.Fatal(err)
}
return &flags.ToolPackage{
Format: "RPM",
ConfigPath: configPath,
ExecutableName: "myapp",
}, func() {
os.RemoveAll(filepath.Join(dir, "bin"))
}
},
wantErr: false,
},
{
name: "should handle case-insensitive format (ARCHLINUX)",
setup: func() (*flags.ToolPackage, func()) {
// Create a temporary config file
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yaml")
err := os.WriteFile(configPath, []byte("name: test"), 0644)
if err != nil {
t.Fatal(err)
}
// Create bin directory
err = os.MkdirAll(filepath.Join(dir, "bin"), 0755)
if err != nil {
t.Fatal(err)
}
return &flags.ToolPackage{
Format: "ARCHLINUX",
ConfigPath: configPath,
ExecutableName: "myapp",
}, func() {
os.RemoveAll(filepath.Join(dir, "bin"))
}
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
options, cleanup := tt.setup()
defer cleanup()
err := ToolPackage(options)
if (err != nil) != tt.wantErr {
t.Errorf("ToolPackage() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr && !strings.Contains(err.Error(), tt.errMsg) {
t.Errorf("ToolPackage() error = %v, want error containing %v", err, tt.errMsg)
}
})
}
}