Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix .resource_types folder and content purge skip #198

Merged
merged 3 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion g10k_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,11 @@ func TestPurgeStaleContent(t *testing.T) {
defer f.Close()
f.WriteString("foobar")
f.Sync()
createOrPurgeDir("/tmp/example/single/.resource_types", funcName)
r, _ := os.Create("/tmp/example/single/.resource_types/test.pp")
defer r.Close()
r.WriteString("foobar")
r.Sync()

cmd := exec.Command(os.Args[0], "-test.run="+funcName+"$")
cmd.Env = append(os.Environ(), "TEST_FOR_CRASH_"+funcName+"=1")
Expand All @@ -2231,7 +2236,7 @@ func TestPurgeStaleContent(t *testing.T) {
if expectedExitCode != exitCode {
t.Errorf("terminated with %v, but we expected exit status %v", exitCode, expectedExitCode)
}
//fmt.Println(string(out))
// fmt.Println(string(out))

expectedLines := []string{
"DEBUG checkForStaleContent(): filepath.Walk'ing directory /tmp/example/single",
Expand Down Expand Up @@ -2259,6 +2264,10 @@ func TestPurgeStaleContent(t *testing.T) {
t.Errorf("Missing module file that should be there")
}

if !fileExists("/tmp/example/single/.resource_types/test.pp") {
t.Errorf("Missing resource_types file /tmp/example/single/.resource_types/test.pp that should be there")
}

purgeDir(cacheDir, funcName)
purgeDir("/tmp/example", funcName)
}
Expand Down
4 changes: 2 additions & 2 deletions stale.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func checkForStaleContent(workDir string) {
}

checkForStaleContent := func(path string, info os.FileInfo, err error) error {
//Debugf("filepath.Walk'ing found path: " + path)
stale := true
if strings.HasSuffix(path, ".resource_types") && isDir(path) {
// never purge .resource_types dir and its content
if strings.HasSuffix(path, ".resource_types") || strings.HasSuffix(filepath.Dir(path), ".resource_types") {
stale = false
} else {
for _, desiredFile := range desiredContent {
Expand Down
2 changes: 1 addition & 1 deletion tests/TestConfigExamplePurgeEnvironment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
:cachedir: '/tmp/g10k'
purge_levels: ['environment']
purge_allowlist: [ '.latest_revision', '.resource_types', '.resource_types/*.pp' ]
purge_allowlist: [ '.latest_revision' ]

sources:
example:
Expand Down