-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(ingredients): added test for fileAbsent.go * refactor: change to types.ErrDeleteRoot instead of custom * test(files): updates to testing output * chore(gitignore): updated ignore to not commit coverage.out * feat(file): updated absent to use MethodPropsSet - fileAbsent uses MethodPropSet for better argument handling - added first pass at file validate for this use case * test(file): initial testing of fileAppend - adds simple parameter testing * test(file): added destination testing for caching - Validates how the caching destination gets handled * test(file): WIP added cache server testing - WIP: added test server to help with caching validation, currently does not work as expected as there seems to be an issue with file providers * test(file): initial work on fileContains testing * test(file): initial testing of fileAppend - validates parameter validation * test(file): initial testing of fileDirectory * refactor(file): move file provider initialization up a level - Moved individual init functions up a level for easier testing - Modified sprout to ensure that this functionality gets registered * test(file): moved test validation to its own file - moved to its own file for easier reading * test(file): fixed Cached test to reflect correct behavior after registration - Change made because local file caching now works since the files are registered * fix(file): fixes issues with error reporting happening incorrectly * test(file): new fileAppend tests added - Fixed test with permissions to correctly reflect behavior - Added tests with empty file and file with content * test(file): remove invalid check * fix(file): fix spelling issues * test(file): updated cache tests for better coverage * test(file): added more append tests * test(file): removed extra dest call in test for cached test * fix(file): updated directory to more correctly report notes - fixed call to f.undef() to append notes from previous actions - added TODOs for where this might fail * test(file): added directory tests for dir_mode * fix(file): moved test to correctly handle not creating a directory * fix(test): fixed file utils to fail more gracefully * test(file): updated dir tests to handle more error cases and tests * test(file): updated caching configuration
- Loading branch information
Showing
20 changed files
with
865 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ configs/ | |
etc | ||
.env | ||
*.zip | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
package main | ||
|
||
import ( | ||
_ "github.com/gogrlx/grlx/ingredients/file/http" | ||
_ "github.com/gogrlx/grlx/ingredients/file/local" | ||
_ "github.com/gogrlx/grlx/ingredients/file/s3" | ||
_ "github.com/gogrlx/grlx/ingredients/file" | ||
_ "github.com/gogrlx/grlx/ingredients/service/systemd" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package file | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/gogrlx/grlx/types" | ||
) | ||
|
||
func TestAbsent(t *testing.T) { | ||
tempDir := t.TempDir() | ||
existingFile := filepath.Join(tempDir, "there-is-a-file-here") | ||
os.Create(existingFile) | ||
sampleDir := filepath.Join(tempDir, "there-is-a-dir-here") | ||
os.Mkdir(sampleDir, 0o755) | ||
file := filepath.Join(sampleDir, "there-is-a-file-here") | ||
os.Create(file) | ||
tests := []struct { | ||
name string | ||
params map[string]interface{} | ||
expected types.Result | ||
error error | ||
test bool | ||
}{ | ||
{ | ||
name: "IncorrectFilename", | ||
params: map[string]interface{}{ | ||
"name": 1, | ||
}, | ||
expected: types.Result{ | ||
Succeeded: false, | ||
Failed: true, | ||
Notes: []fmt.Stringer{}, | ||
}, | ||
error: types.ErrMissingName, | ||
}, | ||
{ | ||
name: "AbsentRoot", | ||
params: map[string]interface{}{ | ||
"name": "/", | ||
}, | ||
expected: types.Result{ | ||
Succeeded: false, | ||
Failed: true, | ||
Notes: []fmt.Stringer{}, | ||
}, | ||
error: types.ErrDeleteRoot, | ||
}, | ||
{ | ||
name: "AbsentNonExistent", | ||
params: map[string]interface{}{ | ||
"name": filepath.Join(tempDir, "there-isnt-a-file-here"), | ||
}, | ||
expected: types.Result{ | ||
Succeeded: true, | ||
Failed: false, | ||
Changed: false, | ||
Notes: []fmt.Stringer{types.Snprintf("%s is already absent", filepath.Join(tempDir, "there-isnt-a-file-here"))}, | ||
}, | ||
error: nil, | ||
}, | ||
{ | ||
name: "AbsentTestRun", | ||
params: map[string]interface{}{ | ||
"name": existingFile, | ||
}, | ||
expected: types.Result{ | ||
Succeeded: true, | ||
Failed: false, | ||
Changed: true, | ||
Notes: []fmt.Stringer{types.Snprintf("%s would be deleted", existingFile)}, | ||
}, | ||
test: true, | ||
}, | ||
{ | ||
name: "AbsentTestActual", | ||
params: map[string]interface{}{ | ||
"name": existingFile, | ||
}, | ||
expected: types.Result{ | ||
Succeeded: true, | ||
Failed: false, | ||
Changed: true, | ||
Notes: []fmt.Stringer{types.Snprintf("%s has been deleted", existingFile)}, | ||
}, | ||
}, | ||
{ | ||
name: "AbesentDeletePopulatedDirs", | ||
params: map[string]interface{}{ | ||
"name": sampleDir, | ||
}, | ||
expected: types.Result{ | ||
Succeeded: false, | ||
Failed: true, | ||
Changed: false, | ||
Notes: []fmt.Stringer{}, | ||
}, | ||
error: &os.PathError{Op: "remove", Path: sampleDir, Err: fmt.Errorf("directory not empty")}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
f := File{ | ||
id: "", | ||
method: "absent", | ||
params: test.params, | ||
} | ||
result, err := f.absent(context.TODO(), test.test) | ||
if test.error != nil && err.Error() != test.error.Error() { | ||
t.Errorf("expected error %v, got %v", test.error, err) | ||
} | ||
compareResults(t, result, test.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.