github.com/tomsquest/goreleaser@v0.34.3-0.20171008022654-7d6ef4d338b3/pipeline/fpm/fpm_test.go (about) 1 package fpm 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/goreleaser/goreleaser/config" 10 "github.com/goreleaser/goreleaser/context" 11 "github.com/goreleaser/goreleaser/internal/testlib" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestDescription(t *testing.T) { 16 assert.NotEmpty(t, Pipe{}.Description()) 17 } 18 19 func TestRunPipeNoFormats(t *testing.T) { 20 var ctx = &context.Context{ 21 Version: "1.0.0", 22 Config: config.Project{}, 23 } 24 testlib.AssertSkipped(t, Pipe{}.Run(ctx)) 25 } 26 27 func TestRunPipe(t *testing.T) { 28 folder, err := ioutil.TempDir("", "archivetest") 29 assert.NoError(t, err) 30 var dist = filepath.Join(folder, "dist") 31 assert.NoError(t, os.Mkdir(dist, 0755)) 32 assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755)) 33 var binPath = filepath.Join(dist, "mybin", "mybin") 34 _, err = os.Create(binPath) 35 assert.NoError(t, err) 36 var ctx = &context.Context{ 37 Version: "1.0.0", 38 Config: config.Project{ 39 ProjectName: "mybin", 40 Dist: dist, 41 FPM: config.FPM{ 42 Formats: []string{"deb", "rpm"}, 43 Dependencies: []string{"make"}, 44 Conflicts: []string{"git"}, 45 Description: "Some description", 46 License: "MIT", 47 Maintainer: "me@me", 48 Vendor: "asdf", 49 Homepage: "https://goreleaser.github.io", 50 }, 51 }, 52 } 53 for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} { 54 ctx.AddBinary(plat, "mybin", "mybin", binPath) 55 } 56 assert.NoError(t, Pipe{}.Run(ctx)) 57 } 58 59 func TestNoFPMInPath(t *testing.T) { 60 var path = os.Getenv("PATH") 61 defer func() { 62 assert.NoError(t, os.Setenv("PATH", path)) 63 }() 64 assert.NoError(t, os.Setenv("PATH", "")) 65 var ctx = &context.Context{ 66 Version: "1.0.0", 67 Config: config.Project{ 68 FPM: config.FPM{ 69 Formats: []string{"deb", "rpm"}, 70 }, 71 }, 72 } 73 assert.EqualError(t, Pipe{}.Run(ctx), ErrNoFPM.Error()) 74 } 75 76 func TestCreateFileDoesntExist(t *testing.T) { 77 folder, err := ioutil.TempDir("", "archivetest") 78 assert.NoError(t, err) 79 var dist = filepath.Join(folder, "dist") 80 assert.NoError(t, os.Mkdir(dist, 0755)) 81 assert.NoError(t, os.Mkdir(filepath.Join(dist, "mybin"), 0755)) 82 var ctx = &context.Context{ 83 Version: "1.0.0", 84 Config: config.Project{ 85 Dist: dist, 86 FPM: config.FPM{ 87 Formats: []string{"deb", "rpm"}, 88 Files: map[string]string{ 89 "testdata/testfile.txt": "/var/lib/test/testfile.txt", 90 }, 91 }, 92 }, 93 } 94 ctx.AddBinary("linuxamd64", "mybin", "mybin", filepath.Join(dist, "mybin", "mybin")) 95 assert.Error(t, Pipe{}.Run(ctx)) 96 } 97 98 func TestRunPipeWithExtraFiles(t *testing.T) { 99 var ctx = &context.Context{ 100 Version: "1.0.0", 101 Config: config.Project{ 102 FPM: config.FPM{ 103 Formats: []string{"deb", "rpm"}, 104 }, 105 }, 106 } 107 assert.NoError(t, Pipe{}.Run(ctx)) 108 }