simplify tests, remove readme injection
This commit is contained in:
		
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,6 +0,0 @@
 | 
				
			|||||||
test:
 | 
					 | 
				
			||||||
	go build -o testdata/app testdata/app.go
 | 
					 | 
				
			||||||
	go build -o appify
 | 
					 | 
				
			||||||
	go test
 | 
					 | 
				
			||||||
	rm appify
 | 
					 | 
				
			||||||
	rm testdata/app
 | 
					 | 
				
			||||||
@@ -24,6 +24,6 @@ appify -name "My Go Application" -icon ./icon.png /path/to/bin
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
It will create a macOS Application.
 | 
					It will create a macOS Application.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## What next?
 | 
					## Upstream
 | 
				
			||||||
 | 
					
 | 
				
			||||||
If you want to build a Go backed web based desktop application, check out our [machinebox/desktop](https://github.com/machinebox/desktop) project.
 | 
					Forked from [machinebox/appify](https://github.com/machinebox/appify).
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							@@ -4,7 +4,6 @@ go 1.24.2
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/JackMordaunt/icns v1.0.0
 | 
						github.com/JackMordaunt/icns v1.0.0
 | 
				
			||||||
	github.com/matryer/is v1.4.1
 | 
					 | 
				
			||||||
	github.com/pkg/errors v0.9.1
 | 
						github.com/pkg/errors v0.9.1
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							@@ -1,7 +1,5 @@
 | 
				
			|||||||
github.com/JackMordaunt/icns v1.0.0 h1:41cNyWyQrG6beMw7m93LFK5o1GhefflsBTkauUkUtG8=
 | 
					github.com/JackMordaunt/icns v1.0.0 h1:41cNyWyQrG6beMw7m93LFK5o1GhefflsBTkauUkUtG8=
 | 
				
			||||||
github.com/JackMordaunt/icns v1.0.0/go.mod h1:ubRqphS0f2OD07BuNaQSuw9uHUVQNBX5g38n6i2bdqM=
 | 
					github.com/JackMordaunt/icns v1.0.0/go.mod h1:ubRqphS0f2OD07BuNaQSuw9uHUVQNBX5g38n6i2bdqM=
 | 
				
			||||||
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
 | 
					 | 
				
			||||||
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
 | 
					 | 
				
			||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
 | 
					github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
 | 
				
			||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
 | 
					github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
 | 
				
			||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 | 
					github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								main.go
									
									
									
									
									
								
							@@ -106,9 +106,6 @@ func run() error {
 | 
				
			|||||||
	if err := tpl.Execute(fplist, info); err != nil {
 | 
						if err := tpl.Execute(fplist, info); err != nil {
 | 
				
			||||||
		return errors.Wrap(err, "execute Info.plist template")
 | 
							return errors.Wrap(err, "execute Info.plist template")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if err := os.WriteFile(filepath.Join(contentsPath, "README"), []byte(readme), 0666); err != nil {
 | 
					 | 
				
			||||||
		return errors.Wrap(err, "ioutil.WriteFile")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -192,11 +189,3 @@ const infoPlistTemplate = `<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			|||||||
	</dict>
 | 
						</dict>
 | 
				
			||||||
</plist>
 | 
					</plist>
 | 
				
			||||||
`
 | 
					`
 | 
				
			||||||
 | 
					 | 
				
			||||||
// readme goes into a README file inside the package for
 | 
					 | 
				
			||||||
// future reference.
 | 
					 | 
				
			||||||
const readme = `Made with Appify by Machine Box
 | 
					 | 
				
			||||||
https://github.com/machinebox/appify
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Inspired by https://gist.github.com/anmoljagetia/d37da67b9d408b35ac753ce51e420132 
 | 
					 | 
				
			||||||
`
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										81
									
								
								main_test.go
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								main_test.go
									
									
									
									
									
								
							@@ -7,22 +7,36 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/matryer/is"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NOTE: Run these tests with `make test`
 | 
					func must[T any](t T, err error) T {
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return t
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func build() func() {
 | 
				
			||||||
 | 
						must(exec.Command("go", "build", "-o", "testdata/app", "testdata/app.go").CombinedOutput())
 | 
				
			||||||
 | 
						must(exec.Command("go", "build", "-o", "appify").CombinedOutput())
 | 
				
			||||||
 | 
						return func() {
 | 
				
			||||||
 | 
							os.RemoveAll("./appify")
 | 
				
			||||||
 | 
							os.RemoveAll("./testdata/app")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Test(t *testing.T) {
 | 
					func Test(t *testing.T) {
 | 
				
			||||||
	is := is.New(t)
 | 
						cleanup := build()
 | 
				
			||||||
	out, err := exec.Command("./appify",
 | 
						defer cleanup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						out := must(exec.Command("./appify",
 | 
				
			||||||
		"-name", "Test",
 | 
							"-name", "Test",
 | 
				
			||||||
		"-icon", "testdata/machina-square.png",
 | 
							"-icon", "testdata/machina-square.png",
 | 
				
			||||||
		"testdata/app").CombinedOutput()
 | 
							"testdata/app").CombinedOutput())
 | 
				
			||||||
	t.Logf("%q", string(out))
 | 
						t.Logf("%q", string(out))
 | 
				
			||||||
	is.NoErr(err)
 | 
					 | 
				
			||||||
	defer os.RemoveAll("Test.app")
 | 
						defer os.RemoveAll("Test.app")
 | 
				
			||||||
	actualAppHash := filehash(t, "testdata/app")
 | 
					
 | 
				
			||||||
 | 
						actualAppHash := filehash("testdata/app")
 | 
				
			||||||
	type file struct {
 | 
						type file struct {
 | 
				
			||||||
		path string
 | 
							path string
 | 
				
			||||||
		perm string
 | 
							perm string
 | 
				
			||||||
@@ -34,34 +48,37 @@ func Test(t *testing.T) {
 | 
				
			|||||||
		{path: "Test.app/Contents/MacOS", perm: "drwxr-xr-x"},
 | 
							{path: "Test.app/Contents/MacOS", perm: "drwxr-xr-x"},
 | 
				
			||||||
		{path: "Test.app/Contents/MacOS/Test.app", perm: "-rwxr-xr-x", hash: actualAppHash},
 | 
							{path: "Test.app/Contents/MacOS/Test.app", perm: "-rwxr-xr-x", hash: actualAppHash},
 | 
				
			||||||
		{path: "Test.app/Contents/Info.plist", perm: "-rw-r--r--", hash: "0cd092b7b884e87617648dbdadb6a804"},
 | 
							{path: "Test.app/Contents/Info.plist", perm: "-rw-r--r--", hash: "0cd092b7b884e87617648dbdadb6a804"},
 | 
				
			||||||
		{path: "Test.app/Contents/README", perm: "-rw-r--r--", hash: "afeb10df47c7f189b848ae44a54e7e06"},
 | 
					 | 
				
			||||||
		{path: "Test.app/Contents/Resources", perm: "drwxr-xr-x"},
 | 
							{path: "Test.app/Contents/Resources", perm: "drwxr-xr-x"},
 | 
				
			||||||
		{path: "Test.app/Contents/Resources/icon.icns", perm: "-rw-r--r--", hash: "23bdc36475094ed8886f319811d3a182"},
 | 
							{path: "Test.app/Contents/Resources/icon.icns", perm: "-rw-r--r--", hash: "23bdc36475094ed8886f319811d3a182"},
 | 
				
			||||||
	} {
 | 
						} {
 | 
				
			||||||
		t.Run(f.path, func(t *testing.T) {
 | 
							t.Run(f.path, func(t *testing.T) {
 | 
				
			||||||
			is := is.New(t)
 | 
								info := must(os.Stat(f.path))
 | 
				
			||||||
			info, err := os.Stat(f.path)
 | 
								if info.Mode().String() != f.perm {
 | 
				
			||||||
			is.NoErr(err)
 | 
									t.Logf("%v != %v", info.Mode().String(), f.perm)
 | 
				
			||||||
			is.Equal(info.Mode().String(), f.perm) // perm
 | 
								}
 | 
				
			||||||
			if f.hash != "" {
 | 
								if f.hash != "" {
 | 
				
			||||||
				actual := filehash(t, f.path)
 | 
									actual := filehash(f.path)
 | 
				
			||||||
				is.Equal(actual, f.hash) // hash
 | 
									if actual != f.hash {
 | 
				
			||||||
 | 
										t.Logf("%v != %v", actual, f.hash)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestWithPListInjection(t *testing.T) {
 | 
					func TestWithPListInjection(t *testing.T) {
 | 
				
			||||||
	is := is.New(t)
 | 
						cleanup := build()
 | 
				
			||||||
	out, err := exec.Command("./appify",
 | 
						defer cleanup()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						out := must(exec.Command("./appify",
 | 
				
			||||||
		"-name", "Test",
 | 
							"-name", "Test",
 | 
				
			||||||
		"-icon", "testdata/machina-square.png",
 | 
							"-icon", "testdata/machina-square.png",
 | 
				
			||||||
		"-plist", "testdata/additionalplist.xml",
 | 
							"-plist", "testdata/additionalplist.xml",
 | 
				
			||||||
		"testdata/app").CombinedOutput()
 | 
							"testdata/app").CombinedOutput())
 | 
				
			||||||
	t.Logf("%q", string(out))
 | 
						t.Logf("%q", string(out))
 | 
				
			||||||
	is.NoErr(err)
 | 
					 | 
				
			||||||
	defer os.RemoveAll("Test.app")
 | 
						defer os.RemoveAll("Test.app")
 | 
				
			||||||
	actualAppHash := filehash(t, "testdata/app")
 | 
					
 | 
				
			||||||
 | 
						actualAppHash := filehash("testdata/app")
 | 
				
			||||||
	type file struct {
 | 
						type file struct {
 | 
				
			||||||
		path string
 | 
							path string
 | 
				
			||||||
		perm string
 | 
							perm string
 | 
				
			||||||
@@ -73,31 +90,29 @@ func TestWithPListInjection(t *testing.T) {
 | 
				
			|||||||
		{path: "Test.app/Contents/MacOS", perm: "drwxr-xr-x"},
 | 
							{path: "Test.app/Contents/MacOS", perm: "drwxr-xr-x"},
 | 
				
			||||||
		{path: "Test.app/Contents/MacOS/Test.app", perm: "-rwxr-xr-x", hash: actualAppHash},
 | 
							{path: "Test.app/Contents/MacOS/Test.app", perm: "-rwxr-xr-x", hash: actualAppHash},
 | 
				
			||||||
		{path: "Test.app/Contents/Info.plist", perm: "-rw-r--r--", hash: "dd977257c7e77dc7739bb4ae70e5f697"},
 | 
							{path: "Test.app/Contents/Info.plist", perm: "-rw-r--r--", hash: "dd977257c7e77dc7739bb4ae70e5f697"},
 | 
				
			||||||
		{path: "Test.app/Contents/README", perm: "-rw-r--r--", hash: "afeb10df47c7f189b848ae44a54e7e06"},
 | 
					 | 
				
			||||||
		{path: "Test.app/Contents/Resources", perm: "drwxr-xr-x"},
 | 
							{path: "Test.app/Contents/Resources", perm: "drwxr-xr-x"},
 | 
				
			||||||
		{path: "Test.app/Contents/Resources/icon.icns", perm: "-rw-r--r--", hash: "23bdc36475094ed8886f319811d3a182"},
 | 
							{path: "Test.app/Contents/Resources/icon.icns", perm: "-rw-r--r--", hash: "23bdc36475094ed8886f319811d3a182"},
 | 
				
			||||||
	} {
 | 
						} {
 | 
				
			||||||
		t.Run(f.path, func(t *testing.T) {
 | 
							t.Run(f.path, func(t *testing.T) {
 | 
				
			||||||
			is := is.New(t)
 | 
								info := must(os.Stat(f.path))
 | 
				
			||||||
			info, err := os.Stat(f.path)
 | 
								if info.Mode().String() != f.perm {
 | 
				
			||||||
			is.NoErr(err)
 | 
									t.Logf("%v != %v", info.Mode().String(), f.perm)
 | 
				
			||||||
			is.Equal(info.Mode().String(), f.perm) // perm
 | 
								}
 | 
				
			||||||
			if f.hash != "" {
 | 
								if f.hash != "" {
 | 
				
			||||||
				actual := filehash(t, f.path)
 | 
									actual := filehash(f.path)
 | 
				
			||||||
				is.Equal(actual, f.hash) // hash
 | 
									if actual != f.hash {
 | 
				
			||||||
 | 
										t.Logf("%v != %v", actual, f.hash)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// filehash gets an md5 hash of the file at path.
 | 
					// filehash gets an md5 hash of the file at path.
 | 
				
			||||||
func filehash(t *testing.T, path string) string {
 | 
					func filehash(path string) string {
 | 
				
			||||||
	is := is.New(t)
 | 
						f := must(os.Open(path))
 | 
				
			||||||
	f, err := os.Open(path)
 | 
					 | 
				
			||||||
	is.NoErr(err)
 | 
					 | 
				
			||||||
	defer f.Close()
 | 
						defer f.Close()
 | 
				
			||||||
	h := md5.New()
 | 
						h := md5.New()
 | 
				
			||||||
	_, err = io.Copy(h, f)
 | 
						must(io.Copy(h, f))
 | 
				
			||||||
	is.NoErr(err)
 | 
					 | 
				
			||||||
	return fmt.Sprintf("%x", h.Sum(nil))
 | 
						return fmt.Sprintf("%x", h.Sum(nil))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user