Add tests for LFS disabled by user case

parent fcbe9f6f
...@@ -282,6 +282,13 @@ func assertLFSFileDownloaded(t *testing.T, build *common.Build) { ...@@ -282,6 +282,13 @@ func assertLFSFileDownloaded(t *testing.T, build *common.Build) {
} }
func assertLFSFileNotDownloaded(t *testing.T, build *common.Build) { func assertLFSFileNotDownloaded(t *testing.T, build *common.Build) {
lfsFilePath := filepath.Join(build.FullProjectDir(), "files", "lfs", "file_1.lfs")
info, err := os.Stat(lfsFilePath)
require.NoError(t, err)
assert.True(t, info.Size() < common.FilesLFSFile1LFSsize, "invalid size of %q file - expected to be less then downloaded LFS object", lfsFilePath)
}
func assertLFSFileNotPresent(t *testing.T, build *common.Build) {
lfsFilePath := filepath.Join(build.FullProjectDir(), "files", "lfs", "file_1.lfs") lfsFilePath := filepath.Join(build.FullProjectDir(), "files", "lfs", "file_1.lfs")
_, err := os.Stat(lfsFilePath) _, err := os.Stat(lfsFilePath)
require.IsType(t, &os.PathError{}, err) require.IsType(t, &os.PathError{}, err)
...@@ -323,7 +330,7 @@ func TestBuildWithGitStrategyNoneWithLFS(t *testing.T) { ...@@ -323,7 +330,7 @@ func TestBuildWithGitStrategyNoneWithLFS(t *testing.T) {
assert.NotContains(t, out, "Created fresh repository") assert.NotContains(t, out, "Created fresh repository")
assert.NotContains(t, out, "Fetching changes") assert.NotContains(t, out, "Fetching changes")
assert.Contains(t, out, "Skipping Git repository setup") assert.Contains(t, out, "Skipping Git repository setup")
assertLFSFileNotDownloaded(t, build) assertLFSFileNotPresent(t, build)
}) })
} }
...@@ -365,7 +372,7 @@ func TestBuildWithGitStrategyFetchWithLFS(t *testing.T) { ...@@ -365,7 +372,7 @@ func TestBuildWithGitStrategyFetchWithLFS(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository") assert.Contains(t, out, "Created fresh repository")
assert.Regexp(t, "Checking out [a-f0-9]+ as", out) assert.Regexp(t, "Checking out [a-f0-9]+ as", out)
assertLFSFileNotDownloaded(t, build) assertLFSFileNotPresent(t, build)
build.GitInfo = common.GetLFSGitInfo(build.GitInfo.RepoURL) build.GitInfo = common.GetLFSGitInfo(build.GitInfo.RepoURL)
...@@ -377,6 +384,35 @@ func TestBuildWithGitStrategyFetchWithLFS(t *testing.T) { ...@@ -377,6 +384,35 @@ func TestBuildWithGitStrategyFetchWithLFS(t *testing.T) {
}) })
} }
func TestBuildWithGitStrategyFetchWithUserDisabledLFS(t *testing.T) {
skipIfGitDoesNotSupportLFS(t)
shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
assert.NoError(t, err)
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_LFS_SKIP_SMUDGE", Value: "1", Public: true})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository")
assert.Regexp(t, "Checking out [a-f0-9]+ as", out)
assertLFSFileNotPresent(t, build)
build.GitInfo = common.GetLFSGitInfo(build.GitInfo.RepoURL)
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_LFS_SKIP_SMUDGE", Value: "1", Public: true})
out, err = runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Fetching changes")
assert.Regexp(t, "Checking out [a-f0-9]+ as", out)
assertLFSFileNotDownloaded(t, build)
})
}
func TestBuildWithGitStrategyFetchNoCheckoutWithoutLFS(t *testing.T) { func TestBuildWithGitStrategyFetchNoCheckoutWithoutLFS(t *testing.T) {
shellstest.OnEachShell(t, func(t *testing.T, shell string) { shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetSuccessfulBuild() successfulBuild, err := common.GetSuccessfulBuild()
...@@ -417,7 +453,7 @@ func TestBuildWithGitStrategyFetchNoCheckoutWithLFS(t *testing.T) { ...@@ -417,7 +453,7 @@ func TestBuildWithGitStrategyFetchNoCheckoutWithLFS(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository") assert.Contains(t, out, "Created fresh repository")
assert.Contains(t, out, "Skipping Git checkout") assert.Contains(t, out, "Skipping Git checkout")
assertLFSFileNotDownloaded(t, build) assertLFSFileNotPresent(t, build)
build.GitInfo = common.GetLFSGitInfo(build.GitInfo.RepoURL) build.GitInfo = common.GetLFSGitInfo(build.GitInfo.RepoURL)
...@@ -425,7 +461,7 @@ func TestBuildWithGitStrategyFetchNoCheckoutWithLFS(t *testing.T) { ...@@ -425,7 +461,7 @@ func TestBuildWithGitStrategyFetchNoCheckoutWithLFS(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, out, "Fetching changes") assert.Contains(t, out, "Fetching changes")
assert.Contains(t, out, "Skipping Git checkout") assert.Contains(t, out, "Skipping Git checkout")
assertLFSFileNotDownloaded(t, build) assertLFSFileNotPresent(t, build)
}) })
} }
...@@ -469,6 +505,25 @@ func TestBuildWithGitStrategyCloneWithLFS(t *testing.T) { ...@@ -469,6 +505,25 @@ func TestBuildWithGitStrategyCloneWithLFS(t *testing.T) {
}) })
} }
func TestBuildWithGitStrategyCloneWithUserDisabledLFS(t *testing.T) {
skipIfGitDoesNotSupportLFS(t)
shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetRemoteSuccessfulLFSBuild()
assert.NoError(t, err)
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "clone"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_LFS_SKIP_SMUDGE", Value: "1", Public: true})
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository")
assertLFSFileNotDownloaded(t, build)
})
}
func TestBuildWithGitStrategyCloneNoCheckoutWithoutLFS(t *testing.T) { func TestBuildWithGitStrategyCloneNoCheckoutWithoutLFS(t *testing.T) {
shellstest.OnEachShell(t, func(t *testing.T, shell string) { shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetSuccessfulBuild() successfulBuild, err := common.GetSuccessfulBuild()
...@@ -508,7 +563,7 @@ func TestBuildWithGitStrategyCloneNoCheckoutWithLFS(t *testing.T) { ...@@ -508,7 +563,7 @@ func TestBuildWithGitStrategyCloneNoCheckoutWithLFS(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository") assert.Contains(t, out, "Created fresh repository")
assert.Contains(t, out, "Skipping Git checkout") assert.Contains(t, out, "Skipping Git checkout")
assertLFSFileNotDownloaded(t, build) assertLFSFileNotPresent(t, build)
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment