Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Apr 8, 2023
1 parent 7b37bf3 commit 4e9bc5b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 13 deletions.
1 change: 0 additions & 1 deletion builder/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,4 @@ func (a *AWS) GetECRLogin() (string, string, error) {
return "", "", fmt.Errorf("invalid authorization data returned by AWS")
}
return decodeECRToken(*result.AuthorizationData[0].AuthorizationToken)

}
6 changes: 4 additions & 2 deletions builder/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/rs/zerolog"
)

const DockerHubMirror = "registry.apppackcdn.net"
const CacheDirectory = "/tmp/apppack-cache"
const (
DockerHubMirror = "registry.apppackcdn.net"
CacheDirectory = "/tmp/apppack-cache"
)

func stripParamPrefix(params map[string]string, prefix string, final *map[string]string) {
for k, v := range params {
Expand Down
1 change: 0 additions & 1 deletion builder/build/postbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ func (b *Build) RunPostbuild() error {
return fmt.Errorf("test failed with exit code %d", exitCode)
}
return nil

}
23 changes: 23 additions & 0 deletions builder/build/prebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (m *MockAWS) CopyFromS3(bucket, prefix, dest string) error {
args := m.Called(bucket, dest)
return args.Error(0)
}

func (m *MockAWS) SyncToS3(src, bucket, prefix string, quiet bool) error {
args := m.Called(src, bucket, prefix, quiet)
return args.Error(0)
Expand All @@ -69,50 +70,62 @@ func (m *MockFilesystem) CreateIfNotExists() error {
args := m.Called()
return args.Error(0)
}

func (m *MockFilesystem) WriteSkipBuild(s string) error {
args := m.Called(s)
return args.Error(0)
}

func (m *MockFilesystem) ShouldSkipBuild(s string) (bool, error) {
args := m.Called(s)
return args.Bool(0), args.Error(1)
}

func (m *MockFilesystem) UnpackTarArchive(r io.ReadCloser) error {
args := m.Called(r)
return args.Error(0)
}

func (m *MockFilesystem) WriteEnvFile(e *map[string]string) error {
args := m.Called(e)
return args.Error(0)
}

func (m *MockFilesystem) ReadEnvFile() (*map[string]string, error) {
args := m.Called()
return args.Get(0).(*map[string]string), args.Error(1)
}

func (m *MockFilesystem) WriteCommitTxt() error {
args := m.Called()
return args.Error(0)
}

func (m *MockFilesystem) MvGitDir() error {
args := m.Called()
return args.Error(0)
}

func (m *MockFilesystem) GitSha() (string, error) {
args := m.Called()
return args.String(0), args.Error(1)
}

func (m *MockFilesystem) EndLogging(f *os.File, s string) error {
args := m.Called(f, s)
return args.Error(0)
}

func (m *MockFilesystem) FileExists(s string) (bool, error) {
args := m.Called(s)
return args.Bool(0), args.Error(1)
}

func (m *MockFilesystem) WriteTomlToFile(s string, v interface{}) error {
args := m.Called(s, v)
return args.Error(0)
}

func (m *MockFilesystem) WriteJsonToFile(s string, v interface{}) error {
args := m.Called(s, v)
return args.Error(0)
Expand All @@ -126,42 +139,52 @@ func (c *MockContainers) Close() error {
args := c.Called()
return args.Error(0)
}

func (c *MockContainers) CreateNetwork(s string) error {
args := c.Called(s)
return args.Error(0)
}

func (c *MockContainers) PullImage(s string) error {
args := c.Called(s)
return args.Error(0)
}

func (c *MockContainers) PushImage(s string) error {
args := c.Called(s)
return args.Error(0)
}

func (c *MockContainers) BuildImage(s string, b *containers.BuildConfig) error {
args := c.Called(s, b)
return args.Error(0)
}

func (c *MockContainers) CreateContainer(s1 string, cfg *container.Config) (*string, error) {
args := c.Called(s1, cfg)
return args.Get(0).(*string), args.Error(1)
}

func (c *MockContainers) RunContainer(s1 string, s2 string, cfg *container.Config) error {
args := c.Called(s1, s2, cfg)
return args.Error(0)
}

func (c *MockContainers) GetContainerFile(s1 string, s2 string) (io.ReadCloser, error) {
args := c.Called(s1, s2)
return args.Get(0).(io.ReadCloser), args.Error(1)
}

func (c *MockContainers) WaitForExit(s string) (int, error) {
args := c.Called(s)
return args.Int(0), args.Error(1)
}

func (c *MockContainers) AttachLogs(s string, w1, w2 io.Writer) error {
args := c.Called(s, w1, w2)
return args.Error(0)
}

func (c *MockContainers) DeleteContainer(s string) error {
args := c.Called(s)
return args.Error(0)
Expand Down
1 change: 0 additions & 1 deletion builder/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var rootCmd = &cobra.Command{
Use: "apppack-builder",
Short: "apppack-builder handles the build pipeline for AppPack",
Run: func(cmd *cobra.Command, args []string) {

},
}

Expand Down
1 change: 0 additions & 1 deletion builder/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func (c *Containers) AttachLogs(containerID string, stdout, stderr io.Writer) er
defer reader.Close()
_, err = stdcopy.StdCopy(stdout, stderr, reader)
return err

}

func (c *Containers) DeleteContainer(containerID string) error {
Expand Down
4 changes: 2 additions & 2 deletions builder/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (f *FileState) CreateIfNotExists() error {
}
if !exists {
f.Log().Debug().Str("filename", filename).Msg("touching file")
err = f.fs.WriteFile(filename, []byte{}, 0644)
err = f.fs.WriteFile(filename, []byte{}, 0o644)
if err != nil {
return err
}
Expand All @@ -87,7 +87,7 @@ func skipBuildFilename(id string) string {
}

func (f *FileState) WriteSkipBuild(id string) error {
return f.fs.WriteFile(skipBuildFilename((id)), []byte{}, 0644)
return f.fs.WriteFile(skipBuildFilename((id)), []byte{}, 0o644)
}

func (f *FileState) ShouldSkipBuild(id string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion builder/filesystem/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (f *FileState) WriteCommitTxt() error {
}
// write the output of the command to commit.txt
f.Log().Debug().Msg("writing commit.txt")
return f.fs.WriteFile("commit.txt", cmd, 0644)
return f.fs.WriteFile("commit.txt", cmd, 0o644)
}

// MvGitDir moves the git directory to the root of the project
Expand Down
9 changes: 5 additions & 4 deletions builder/filesystem/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestWriteCommitTxt(t *testing.T) {
t.Errorf("Unexpected content in commit.txt file. Expected: %s, got: '%s'", testText, string(content))
}
}

func TestMvGitDirNoOp(t *testing.T) {
// setup mock filesystem
mockFs := afero.Afero{
Expand All @@ -76,7 +77,7 @@ func TestMvGitDirNoOp(t *testing.T) {
}

// create .git file as directory
err = mockFs.Mkdir(".git", 0755)
err = mockFs.Mkdir(".git", 0o755)
if err != nil {
t.Error("Failed to create .git directory")
}
Expand Down Expand Up @@ -118,13 +119,13 @@ func TestMvGitDir(t *testing.T) {
}

gitDir := "/path/to/git/dir"
err := mockFs.Mkdir(gitDir, 0755)
err := mockFs.Mkdir(gitDir, 0o755)
if err != nil {
t.Error("Failed to create git directory")
}

// create .git file with correct format
err = mockFs.WriteFile(".git", []byte("gitdir: "+gitDir), 0644)
err = mockFs.WriteFile(".git", []byte("gitdir: "+gitDir), 0o644)
if err != nil {
t.Error("Failed to create .git file with correct format")
}
Expand Down Expand Up @@ -158,7 +159,7 @@ func TestMvGitDirFileInvalid(t *testing.T) {
}

// create .git file with incorrect format
err := mockFs.WriteFile(".git", []byte("incorrect format"), 0644)
err := mockFs.WriteFile(".git", []byte("incorrect format"), 0o644)
if err != nil {
t.Error("Failed to create .git file with incorrect format")
}
Expand Down

0 comments on commit 4e9bc5b

Please sign in to comment.