Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit a837705

Browse files
committed
Use filepath instead of path
Signed-off-by: Christopher Crone <[email protected]>
1 parent 6262249 commit a837705

File tree

12 files changed

+61
-61
lines changed

12 files changed

+61
-61
lines changed

e2e/binary_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io/ioutil"
88
"os"
99
"os/exec"
10-
"path"
10+
"path/filepath"
1111
"runtime"
1212
"testing"
1313

@@ -65,10 +65,10 @@ func TestRenderBinary(t *testing.T) {
6565
assert.NilError(t, err, "unable to get apps")
6666
for _, app := range apps {
6767
t.Log("testing", app.Name())
68-
settings, overrides, env := gather(t, path.Join("render", app.Name()))
68+
settings, overrides, env := gather(t, filepath.Join("render", app.Name()))
6969
args := []string{
7070
"render",
71-
path.Join("render", app.Name()),
71+
filepath.Join("render", app.Name()),
7272
}
7373
for _, s := range settings {
7474
args = append(args, "-f", s)
@@ -82,7 +82,7 @@ func TestRenderBinary(t *testing.T) {
8282
t.Logf("executing with %v", args)
8383
cmd := exec.Command(dockerApp, args...)
8484
output, err := cmd.CombinedOutput()
85-
checkResult(t, string(output), err, path.Join("render", app.Name()))
85+
checkResult(t, string(output), err, filepath.Join("render", app.Name()))
8686
}
8787
}
8888

@@ -105,8 +105,8 @@ func TestInitBinary(t *testing.T) {
105105
envData := "# some comment\nNGINX_VERSION=latest"
106106
inputDir := randomName("app_input_")
107107
os.Mkdir(inputDir, 0755)
108-
ioutil.WriteFile(path.Join(inputDir, "docker-compose.yml"), []byte(composeData), 0644)
109-
ioutil.WriteFile(path.Join(inputDir, ".env"), []byte(envData), 0644)
108+
ioutil.WriteFile(filepath.Join(inputDir, "docker-compose.yml"), []byte(composeData), 0644)
109+
ioutil.WriteFile(filepath.Join(inputDir, ".env"), []byte(envData), 0644)
110110
defer os.RemoveAll(inputDir)
111111

112112
testAppName := randomName("app_")
@@ -117,15 +117,15 @@ func TestInitBinary(t *testing.T) {
117117
"init",
118118
testAppName,
119119
"-c",
120-
path.Join(inputDir, "docker-compose.yml"),
120+
filepath.Join(inputDir, "docker-compose.yml"),
121121
}
122122
cmd := exec.Command(dockerApp, args...)
123123
output, err := cmd.CombinedOutput()
124124
if err != nil {
125125
fmt.Println(string(output))
126126
}
127127
assert.NilError(t, err)
128-
meta, err := ioutil.ReadFile(path.Join(dirName, "metadata.yml"))
128+
meta, err := ioutil.ReadFile(filepath.Join(dirName, "metadata.yml"))
129129
assert.NilError(t, err)
130130
manifest := fs.Expected(
131131
t,

e2e/render_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package e2e
33
import (
44
"io/ioutil"
55
"os"
6-
"path"
6+
"path/filepath"
77
"strings"
88
"testing"
99

@@ -24,16 +24,16 @@ func gather(t *testing.T, dir string) ([]string, []string, map[string]string) {
2424
for _, f := range content {
2525
split := strings.SplitN(f.Name(), "-", 2)
2626
if split[0] == "settings" {
27-
settings = append(settings, path.Join(dir, f.Name()))
27+
settings = append(settings, filepath.Join(dir, f.Name()))
2828
}
2929
if split[0] == "override" {
30-
overrides = append(overrides, path.Join(dir, f.Name()))
30+
overrides = append(overrides, filepath.Join(dir, f.Name()))
3131
}
3232
}
3333
// look for emulated command line env
3434
env := make(map[string]string)
35-
if _, err = os.Stat(path.Join(dir, "env.yml")); err == nil {
36-
envRaw, err := ioutil.ReadFile(path.Join(dir, "env.yml"))
35+
if _, err = os.Stat(filepath.Join(dir, "env.yml")); err == nil {
36+
envRaw, err := ioutil.ReadFile(filepath.Join(dir, "env.yml"))
3737
assert.NilError(t, err, "unable to read file")
3838
err = yaml.Unmarshal(envRaw, &env)
3939
assert.NilError(t, err, "unable to unmarshal env")
@@ -43,14 +43,14 @@ func gather(t *testing.T, dir string) ([]string, []string, map[string]string) {
4343

4444
func checkResult(t *testing.T, result string, resultErr error, dir string) {
4545
if resultErr != nil {
46-
ee := path.Join(dir, "expectedError.txt")
46+
ee := filepath.Join(dir, "expectedError.txt")
4747
if _, err := os.Stat(ee); err != nil {
4848
assert.NilError(t, resultErr, "unexpected render error")
4949
}
5050
expectedErr := readFile(t, ee)
5151
assert.ErrorContains(t, resultErr, expectedErr)
5252
} else {
53-
expectedRender := readFile(t, path.Join(dir, "expected.txt"))
53+
expectedRender := readFile(t, filepath.Join(dir, "expected.txt"))
5454
assert.Equal(t, string(expectedRender), result, "rendering missmatch")
5555
}
5656
}
@@ -60,16 +60,16 @@ func TestRender(t *testing.T) {
6060
assert.NilError(t, err, "unable to get apps")
6161
for _, app := range apps {
6262
t.Log("testing", app.Name())
63-
settings, overrides, env := gather(t, path.Join("render", app.Name()))
63+
settings, overrides, env := gather(t, filepath.Join("render", app.Name()))
6464
// run the render
65-
config, resultErr := renderer.Render(path.Join("render", app.Name()), overrides, settings, env)
65+
config, resultErr := renderer.Render(filepath.Join("render", app.Name()), overrides, settings, env)
6666
var result string
6767
if resultErr == nil {
6868
var bytes []byte
6969
bytes, resultErr = yaml.Marshal(config)
7070
result = string(bytes)
7171
}
72-
checkResult(t, result, resultErr, path.Join("render", app.Name()))
72+
checkResult(t, result, resultErr, filepath.Join("render", app.Name()))
7373
}
7474
}
7575

image/image.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"os"
66
"os/exec"
7-
"path"
7+
"path/filepath"
88

99
"github.com/docker/lunchbox/packager"
1010
"github.com/docker/lunchbox/renderer"
@@ -32,12 +32,12 @@ func Add(appname string, services []string, composeFiles []string, settingsFile
3232
if err != nil {
3333
return err
3434
}
35-
os.Mkdir(path.Join(appname, "images"), 0755)
35+
os.Mkdir(filepath.Join(appname, "images"), 0755)
3636
for _, s := range config.Services {
3737
if len(services) != 0 && !contains(services, s.Name) {
3838
continue
3939
}
40-
cmd := exec.Command("docker", "save", "-o", path.Join(appname, "images", s.Name), s.Image)
40+
cmd := exec.Command("docker", "save", "-o", filepath.Join(appname, "images", s.Name), s.Image)
4141
output, err := cmd.CombinedOutput()
4242
if err != nil {
4343
fmt.Println(output)
@@ -68,7 +68,7 @@ func Load(appname string, services []string) error {
6868
return err
6969
}
7070
defer cleanup()
71-
imageDir, err := os.Open(path.Join(appname, "images"))
71+
imageDir, err := os.Open(filepath.Join(appname, "images"))
7272
if err != nil {
7373
return fmt.Errorf("no images found in app")
7474
}
@@ -80,7 +80,7 @@ func Load(appname string, services []string) error {
8080
if len(services) != 0 && !contains(services, i) {
8181
continue
8282
}
83-
cmd := exec.Command("docker", "load", "-i", path.Join(appname, "images", i))
83+
cmd := exec.Command("docker", "load", "-i", filepath.Join(appname, "images", i))
8484
output, err := cmd.CombinedOutput()
8585
if err != nil {
8686
fmt.Println(output)

packager/extract.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"io"
77
"io/ioutil"
88
"os"
9-
"path"
9+
"path/filepath"
1010
"strings"
1111

1212
"github.com/docker/lunchbox/constants"
@@ -43,7 +43,7 @@ func findApp() (string, error) {
4343
if hit == "" {
4444
return "", fmt.Errorf("no app found in current directory")
4545
}
46-
return path.Join(cwd, hit), nil
46+
return filepath.Join(cwd, hit), nil
4747
}
4848

4949
// Extract extracts the app content if argument is an archive, or does nothing if a dir.

packager/init.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"os"
88
"os/user"
9-
"path"
9+
"path/filepath"
1010
"strings"
1111

1212
"github.com/docker/lunchbox/types"
@@ -56,10 +56,10 @@ func initFromScratch(name string) error {
5656
}
5757

5858
dirName := utils.DirNameFromAppName(name)
59-
if err := utils.CreateFileWithData(path.Join(dirName, "docker-compose.yml"), composeData); err != nil {
59+
if err := utils.CreateFileWithData(filepath.Join(dirName, "docker-compose.yml"), composeData); err != nil {
6060
return err
6161
}
62-
return utils.CreateFileWithData(path.Join(dirName, "settings.yml"), []byte{'\n'})
62+
return utils.CreateFileWithData(filepath.Join(dirName, "settings.yml"), []byte{'\n'})
6363
}
6464

6565
func parseEnv(env string, target map[string]string) {
@@ -160,7 +160,7 @@ func initFromComposeFile(name string, composeFile string) error {
160160
return errors.Wrap(err, "failed to read compose file")
161161
}
162162
settings := make(map[string]string)
163-
envRaw, err := ioutil.ReadFile(path.Join(path.Dir(composeFile), ".env"))
163+
envRaw, err := ioutil.ReadFile(filepath.Join(filepath.Dir(composeFile), ".env"))
164164
if err == nil {
165165
parseEnv(string(envRaw), settings)
166166
}
@@ -179,11 +179,11 @@ func initFromComposeFile(name string, composeFile string) error {
179179
if err != nil {
180180
return errors.Wrap(err, "failed to marshal settings")
181181
}
182-
err = ioutil.WriteFile(path.Join(dirName, "docker-compose.yml"), composeRaw, 0644)
182+
err = ioutil.WriteFile(filepath.Join(dirName, "docker-compose.yml"), composeRaw, 0644)
183183
if err != nil {
184184
return errors.Wrap(err, "failed to write docker-compose.yml")
185185
}
186-
err = ioutil.WriteFile(path.Join(dirName, "settings.yml"), settingsYAML, 0644)
186+
err = ioutil.WriteFile(filepath.Join(dirName, "settings.yml"), settingsYAML, 0644)
187187
if err != nil {
188188
return errors.Wrap(err, "failed to write settings.yml")
189189
}
@@ -203,7 +203,7 @@ func writeMetadataFile(name, dirName string) error {
203203
if err != nil {
204204
return err
205205
}
206-
return utils.CreateFileWithData(path.Join(dirName, "metadata.yml"), data)
206+
return utils.CreateFileWithData(filepath.Join(dirName, "metadata.yml"), data)
207207
}
208208

209209
func newMetadata(name string) types.AppMetadata {

packager/init_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/hex"
66
"io/ioutil"
77
"os"
8-
"path"
8+
"path/filepath"
99
"testing"
1010

1111
"github.com/gotestyourself/gotestyourself/assert"
@@ -33,8 +33,8 @@ func TestInitFromComposeFile(t *testing.T) {
3333
envData := "# some comment\nNGINX_VERSION=latest"
3434
inputDir := randomName("app_input_")
3535
os.Mkdir(inputDir, 0755)
36-
ioutil.WriteFile(path.Join(inputDir, "docker-compose.yml"), []byte(composeData), 0644)
37-
ioutil.WriteFile(path.Join(inputDir, ".env"), []byte(envData), 0644)
36+
ioutil.WriteFile(filepath.Join(inputDir, "docker-compose.yml"), []byte(composeData), 0644)
37+
ioutil.WriteFile(filepath.Join(inputDir, ".env"), []byte(envData), 0644)
3838
defer os.RemoveAll(inputDir)
3939

4040
testAppName := randomName("app_")
@@ -43,7 +43,7 @@ func TestInitFromComposeFile(t *testing.T) {
4343
assert.NilError(t, err)
4444
defer os.RemoveAll(dirName)
4545

46-
err = initFromComposeFile(testAppName, path.Join(inputDir, "docker-compose.yml"))
46+
err = initFromComposeFile(testAppName, filepath.Join(inputDir, "docker-compose.yml"))
4747
assert.NilError(t, err)
4848

4949
manifest := fs.Expected(

packager/inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package packager
33
import (
44
"fmt"
55
"io/ioutil"
6-
"path"
6+
"path/filepath"
77

88
"github.com/docker/lunchbox/types"
99
yaml "gopkg.in/yaml.v2"
@@ -16,7 +16,7 @@ func Inspect(appname string) error {
1616
return err
1717
}
1818
defer cleanup()
19-
metaFile := path.Join(appname, "metadata.yml")
19+
metaFile := filepath.Join(appname, "metadata.yml")
2020
metaContent, err := ioutil.ReadFile(metaFile)
2121
if err != nil {
2222
return err

packager/packing.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"io"
77
"io/ioutil"
88
"os"
9-
"path"
9+
"path/filepath"
1010

1111
"github.com/docker/lunchbox/constants"
1212
"github.com/docker/lunchbox/utils"
@@ -64,19 +64,19 @@ func Pack(appname, output string) error {
6464
tarout := tar.NewWriter(target)
6565
files := []string{"metadata.yml", "docker-compose.yml", "settings.yml"}
6666
for _, f := range files {
67-
err = tarAdd(tarout, f, path.Join(appname, f))
67+
err = tarAdd(tarout, f, filepath.Join(appname, f))
6868
if err != nil {
6969
return err
7070
}
7171
}
7272
// check for images
73-
_, err = os.Stat(path.Join(appname, "images"))
73+
_, err = os.Stat(filepath.Join(appname, "images"))
7474
if err == nil {
7575
err = tarAddDir(tarout, "images")
7676
if err != nil {
7777
return err
7878
}
79-
imageDir, err := os.Open(path.Join(appname, "images"))
79+
imageDir, err := os.Open(filepath.Join(appname, "images"))
8080
if err != nil {
8181
return err
8282
}
@@ -85,7 +85,7 @@ func Pack(appname, output string) error {
8585
return err
8686
}
8787
for _, i := range images {
88-
err = tarAdd(tarout, path.Join("images", i), path.Join(appname, "images", i))
88+
err = tarAdd(tarout, filepath.Join("images", i), filepath.Join(appname, "images", i))
8989
if err != nil {
9090
return err
9191
}
@@ -108,7 +108,7 @@ func Unpack(appname, targetDir string) error {
108108
if s.IsDir() {
109109
return fmt.Errorf("app already extracted")
110110
}
111-
out := path.Join(targetDir, utils.AppNameFromDir(appname)+constants.AppExtension)
111+
out := filepath.Join(targetDir, utils.AppNameFromDir(appname)+constants.AppExtension)
112112
err = os.Mkdir(out, 0755)
113113
if err != nil {
114114
return err

packager/registry.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"math/rand"
99
"os"
1010
"os/exec"
11-
"path"
11+
"path/filepath"
1212
"strings"
1313

1414
"github.com/docker/lunchbox/constants"
@@ -31,9 +31,9 @@ func Save(appname, prefix, tag string) error {
3131
FROM scratch
3232
COPY / /
3333
`
34-
df := path.Join(appname, "__Dockerfile-docker-app__")
34+
df := filepath.Join(appname, "__Dockerfile-docker-app__")
3535
ioutil.WriteFile(df, []byte(dockerfile), 0644)
36-
di := path.Join(appname, ".dockerignore")
36+
di := filepath.Join(appname, ".dockerignore")
3737
ioutil.WriteFile(di, []byte("__Dockerfile-docker-app__\n.dockerignore"), 0644)
3838
args := []string{"build", "-t", prefix + appName(appname) + constants.AppExtension + ":" + tag, "-f", df, appname}
3939
cmd := exec.Command("docker", args...)
@@ -48,7 +48,7 @@ COPY / /
4848

4949
// Load loads an app from docker
5050
func Load(repotag string) error {
51-
file := path.Join(os.TempDir(), "docker-app-"+fmt.Sprintf("%v%v", rand.Int63(), rand.Int63()))
51+
file := filepath.Join(os.TempDir(), "docker-app-"+fmt.Sprintf("%v%v", rand.Int63(), rand.Int63()))
5252
cmd := exec.Command("docker", "save", "-o", file, repotag)
5353
output, err := cmd.CombinedOutput()
5454
if err != nil {
@@ -70,7 +70,7 @@ func Load(repotag string) error {
7070
if err != nil {
7171
return errors.Wrap(err, "error reading next tar header")
7272
}
73-
if path.Base(header.Name) == "layer.tar" {
73+
if filepath.Base(header.Name) == "layer.tar" {
7474
data := make([]byte, header.Size)
7575
_, err := tarReader.Read(data)
7676
if err != nil && err != io.EOF {

0 commit comments

Comments
 (0)