mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 18:48:33 -04:00
fix: fixing leaks.
This commit is contained in:
129
scan_test.odin
129
scan_test.odin
@@ -7,88 +7,81 @@ import "core:testing"
|
||||
|
||||
@(test)
|
||||
test_scan_path_finds_gitignored_env_files :: proc(t: ^testing.T) {
|
||||
if !can_scan() {
|
||||
return
|
||||
}
|
||||
feats := check_features()
|
||||
testing.expect(t, cant_scan(feats) == false)
|
||||
|
||||
base := fmt.aprintf("/tmp/envr-scan-test-%d", os.get_pid())
|
||||
os.mkdir_all(base)
|
||||
defer os.remove_all(base)
|
||||
base := fmt.aprintf("/tmp/envr-scan-test-%d", os.get_pid())
|
||||
os.mkdir_all(base)
|
||||
defer os.remove_all(base)
|
||||
|
||||
git_init := os.Process_Desc{
|
||||
command = []string{"git", "-c", "advice.defaultBranchName=false", "init"},
|
||||
working_dir = base,
|
||||
stdout = os.stderr,
|
||||
stderr = os.stderr,
|
||||
}
|
||||
p, err := os.process_start(git_init)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, wait_err := os.process_wait(p)
|
||||
if wait_err != nil {
|
||||
return
|
||||
}
|
||||
git_init := os.Process_Desc {
|
||||
command = []string{"git", "-c", "advice.defaultBranchName=false", "init"},
|
||||
working_dir = base,
|
||||
stdout = os.stderr,
|
||||
stderr = os.stderr,
|
||||
}
|
||||
p, err := os.process_start(git_init)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, wait_err := os.process_wait(p)
|
||||
if wait_err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
gitignore_path := fmt.aprintf("%s/.gitignore", base)
|
||||
_ = os.write_entire_file(gitignore_path, ".env*\n")
|
||||
gitignore_path := fmt.aprintf("%s/.gitignore", base)
|
||||
_ = os.write_entire_file(gitignore_path, ".env*\n")
|
||||
|
||||
_ = os.write_entire_file(fmt.aprintf("%s/.env", base), "SECRET=1")
|
||||
_ = os.write_entire_file(fmt.aprintf("%s/.env.testing", base), "TEST=1")
|
||||
_ = os.write_entire_file(fmt.aprintf("%s/config.yaml", base), "key: value")
|
||||
_ = os.write_entire_file(fmt.aprintf("%s/.env", base), "SECRET=1")
|
||||
_ = os.write_entire_file(fmt.aprintf("%s/.env.testing", base), "TEST=1")
|
||||
_ = os.write_entire_file(fmt.aprintf("%s/config.yaml", base), "key: value")
|
||||
|
||||
cfg := Config{
|
||||
ScanConfig = ScanConfig{
|
||||
Matcher = "\\.env",
|
||||
Exclude = []string{},
|
||||
Include = []string{},
|
||||
},
|
||||
}
|
||||
cfg := Config {
|
||||
ScanConfig = ScanConfig{Matcher = "\\.env", Exclude = []string{}, Include = []string{}},
|
||||
}
|
||||
|
||||
results, ok := scan_path(base, cfg)
|
||||
testing.expect(t, ok, "scan_path should succeed")
|
||||
results, ok := scan_path(base, cfg)
|
||||
defer delete(results)
|
||||
testing.expect(t, ok, "scan_path should succeed")
|
||||
|
||||
found_env := false
|
||||
found_testing := false
|
||||
found_config := false
|
||||
found_env := false
|
||||
found_testing := false
|
||||
found_config := false
|
||||
|
||||
for path in results {
|
||||
_, filename := filepath.split(path)
|
||||
if filename == ".env" {
|
||||
found_env = true
|
||||
}
|
||||
if filename == ".env.testing" {
|
||||
found_testing = true
|
||||
}
|
||||
if filename == "config.yaml" {
|
||||
found_config = true
|
||||
}
|
||||
}
|
||||
for path in results {
|
||||
_, filename := filepath.split(path)
|
||||
if filename == ".env" {
|
||||
found_env = true
|
||||
}
|
||||
if filename == ".env.testing" {
|
||||
found_testing = true
|
||||
}
|
||||
if filename == "config.yaml" {
|
||||
found_config = true
|
||||
}
|
||||
}
|
||||
|
||||
testing.expect(t, found_env, "should find .env (gitignored)")
|
||||
testing.expect(t, found_testing, "should find .env.testing (gitignored)")
|
||||
testing.expect(t, !found_config, "should NOT find config.yaml (not gitignored)")
|
||||
testing.expect(t, found_env, "should find .env (gitignored)")
|
||||
testing.expect(t, found_testing, "should find .env.testing (gitignored)")
|
||||
testing.expect(t, !found_config, "should NOT find config.yaml (not gitignored)")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_scan_path_empty_dir :: proc(t: ^testing.T) {
|
||||
if !can_scan() {
|
||||
return
|
||||
}
|
||||
feats := check_features()
|
||||
testing.expect(t, cant_scan(feats) == false)
|
||||
|
||||
base := fmt.aprintf("/tmp/envr-scan-empty-%d", os.get_pid())
|
||||
os.mkdir_all(base)
|
||||
defer os.remove_all(base)
|
||||
base := fmt.aprintf("/tmp/envr-scan-empty-%d", os.get_pid())
|
||||
os.mkdir_all(base)
|
||||
defer os.remove_all(base)
|
||||
|
||||
cfg := Config{
|
||||
ScanConfig = ScanConfig{
|
||||
Matcher = "\\.env",
|
||||
Exclude = []string{},
|
||||
Include = []string{},
|
||||
},
|
||||
}
|
||||
cfg := Config {
|
||||
ScanConfig = ScanConfig{Matcher = "\\.env", Exclude = []string{}, Include = []string{}},
|
||||
}
|
||||
|
||||
results, ok := scan_path(base, cfg)
|
||||
testing.expect(t, ok, "scan_path should succeed")
|
||||
testing.expect(t, len(results) == 0, fmt.aprintf("expected 0 results, got %d", len(results)))
|
||||
results, ok := scan_path(base, cfg)
|
||||
defer delete(results)
|
||||
testing.expect(t, ok, "scan_path should succeed")
|
||||
testing.expect(t, len(results) == 0, fmt.aprintf("expected 0 results, got %d", len(results)))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user