Skip to content

Commit 890130a

Browse files
Add appendonly no case in directory creation test
1 parent e28a420 commit 890130a

File tree

5 files changed

+385
-271
lines changed

5 files changed

+385
-271
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package filesystem_assertion
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"al.essio.dev/pkg/shellescape"
8+
)
9+
10+
type DirDoesNotExistAssertion struct {
11+
AbsolutePath string
12+
}
13+
14+
func (a *DirDoesNotExistAssertion) Run() FilesystemAssertionResult {
15+
if a.AbsolutePath == "" {
16+
panic("Codecrafters Internal Error - AbsolutePath in DirDoesNotExistAssertion cannot be empty")
17+
}
18+
19+
info, err := os.Stat(a.AbsolutePath)
20+
escapedPath := shellescape.Quote(a.AbsolutePath)
21+
22+
if err != nil {
23+
if os.IsNotExist(err) {
24+
return FilesystemAssertionResult{
25+
Logs: []FilesystemAssertionLog{
26+
NewFilesystemAssertionLog(_SUCCESS, fmt.Sprintf("✔ Directory %s does not exist", escapedPath)),
27+
},
28+
}
29+
}
30+
return FilesystemAssertionResult{
31+
Err: fmt.Errorf("Error retrieving directory info of %s: %w", escapedPath, err),
32+
}
33+
}
34+
35+
if info.IsDir() {
36+
return FilesystemAssertionResult{
37+
Err: fmt.Errorf("Expected directory %s to not exist, found directory", escapedPath),
38+
}
39+
}
40+
41+
return FilesystemAssertionResult{
42+
Err: fmt.Errorf("Expected directory %s to not exist, found non-directory file", escapedPath),
43+
}
44+
}

internal/redis_executable/redis_executable.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ type RedisExecutable struct {
1414
executable *executable.Executable
1515
logger *logger.Logger
1616
args []string
17+
18+
// isRunning is set to true after a successful .Start()
19+
// and set to false after a successful .Kill()
20+
isRunning bool
1721
}
1822

1923
func NewRedisExecutable(stageHarness *test_case_harness.TestCaseHarness) *RedisExecutable {
@@ -48,6 +52,7 @@ func (b *RedisExecutable) Run(args ...string) error {
4852
return err
4953
}
5054

55+
b.isRunning = true
5156
return nil
5257
}
5358

@@ -56,12 +61,18 @@ func (b *RedisExecutable) HasExited() bool {
5661
}
5762

5863
func (b *RedisExecutable) Kill() error {
64+
if !b.isRunning {
65+
return nil
66+
}
67+
5968
b.logger.Debugf("Terminating program")
6069
if err := b.executable.Kill(); err != nil {
6170
b.logger.Debugf("Error terminating program: '%v'", err)
6271
return err
6372
}
6473

6574
b.logger.Debugf("Program terminated successfully")
75+
76+
b.isRunning = false
6677
return nil // When does this happen?
6778
}

0 commit comments

Comments
 (0)