diff --git a/builder/aws/aws.go b/builder/aws/aws.go index fdd4d92..3d7a1b4 100644 --- a/builder/aws/aws.go +++ b/builder/aws/aws.go @@ -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) - } diff --git a/builder/build/build.go b/builder/build/build.go index 80b732d..61f7621 100644 --- a/builder/build/build.go +++ b/builder/build/build.go @@ -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 { diff --git a/builder/build/postbuild.go b/builder/build/postbuild.go index fa9d91a..cdb99e3 100644 --- a/builder/build/postbuild.go +++ b/builder/build/postbuild.go @@ -113,5 +113,4 @@ func (b *Build) RunPostbuild() error { return fmt.Errorf("test failed with exit code %d", exitCode) } return nil - } diff --git a/builder/build/prebuild_test.go b/builder/build/prebuild_test.go index a92f514..3418745 100644 --- a/builder/build/prebuild_test.go +++ b/builder/build/prebuild_test.go @@ -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) @@ -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) @@ -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) diff --git a/builder/cmd/root.go b/builder/cmd/root.go index 5965dc1..a97b572 100644 --- a/builder/cmd/root.go +++ b/builder/cmd/root.go @@ -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) { - }, } diff --git a/builder/containers/containers.go b/builder/containers/containers.go index 7ba8ff1..53a4866 100644 --- a/builder/containers/containers.go +++ b/builder/containers/containers.go @@ -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 { diff --git a/builder/filesystem/filesystem.go b/builder/filesystem/filesystem.go index 6e474f9..73c9af0 100644 --- a/builder/filesystem/filesystem.go +++ b/builder/filesystem/filesystem.go @@ -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 } @@ -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) { diff --git a/builder/filesystem/git.go b/builder/filesystem/git.go index 021dd25..62de821 100644 --- a/builder/filesystem/git.go +++ b/builder/filesystem/git.go @@ -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 diff --git a/builder/filesystem/git_test.go b/builder/filesystem/git_test.go index 2eac98d..5822296 100644 --- a/builder/filesystem/git_test.go +++ b/builder/filesystem/git_test.go @@ -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{ @@ -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") } @@ -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") } @@ -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") }