Skip to content

Commit

Permalink
Add config model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-newey committed Sep 30, 2024
1 parent fdcdce6 commit c7baa97
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 39 deletions.
9 changes: 6 additions & 3 deletions src/commands/commands_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package commands
package commands_test

import "testing"
import (
"hudson-newey/2rm/src/commands"
"testing"
)

func TestCommandsEcho(t *testing.T) {
Execute("echo 'Hello World'")
commands.Execute("echo 'Hello World'")
}
5 changes: 3 additions & 2 deletions src/config/parse_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config
package config_test

import (
"hudson-newey/2rm/src/config"
"hudson-newey/2rm/src/models"
"path/filepath"
"reflect"
Expand All @@ -14,7 +15,7 @@ func assertConfig(t *testing.T, configPath string, expectedConfig models.Config)
t.Errorf("Failed to get absolute path")
}

realizedConfig := ParseConfig(absolutePath)
realizedConfig := config.ParseConfig(absolutePath)

if !reflect.DeepEqual(expectedConfig, realizedConfig) {
t.Errorf("Expected %v but got %v", expectedConfig, realizedConfig)
Expand Down
105 changes: 76 additions & 29 deletions src/models/config_test.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,102 @@
package models
package models_test

import "testing"
import (
"hudson-newey/2rm/src/config"
"hudson-newey/2rm/src/models"
"path/filepath"
"testing"
)

func loadConfig(path string) models.Config {
testConfigDir := "../../tests/assets/configs/"
absolutePath, _ := filepath.Abs(testConfigDir + path)
return config.ParseConfig(absolutePath)
}

func TestShouldHardDelete(t *testing.T) {
t.Fatal("This test needs to be implemented!")
testedConfig := loadConfig("valid.yml")

expected := true
realized := testedConfig.ShouldHardDelete("node_modules/")

if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestShouldHardDeleteFalse(t *testing.T) {
t.Fatal("This test needs to be implemented!")
func TestShouldNotHardDelete(t *testing.T) {
testedConfig := loadConfig("valid.yml")

expected := false
realized := testedConfig.ShouldHardDelete("src/")

if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestShouldHardDeleteEmpty(t *testing.T) {
t.Fatal("This test needs to be implemented!")
testedConfig := loadConfig("only_backups.yml")

expected := false
realized := testedConfig.ShouldHardDelete("node_modules/")

if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestShouldSoftDelete(t *testing.T) {
t.Fatal("This test needs to be implemented!")
testedConfig := loadConfig("valid.yml")

expected := true
realized := testedConfig.ShouldSoftDelete("file.bak")

if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestShouldSoftDeleteFalse(t *testing.T) {
t.Fatal("This test needs to be implemented!")
func TestShouldNotSoftDelete(t *testing.T) {
testedConfig := loadConfig("valid.yml")

expected := false
realized := testedConfig.ShouldSoftDelete("file.txt")

if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestShouldSoftDeleteEmpty(t *testing.T) {
t.Fatal("This test needs to be implemented!")
}
testedConfig := loadConfig("only_backups.yml")

func TestSoftDeleteDir(t *testing.T) {
t.Fatal("This test needs to be implemented!")
}
expected := false
realized := testedConfig.ShouldSoftDelete("file.bak")

func TestSoftDeleteDirDefault(t *testing.T) {
t.Fatal("This test needs to be implemented!")
if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestMatchesPatternFile(t *testing.T) {
t.Fatal("This test needs to be implemented!")
}
func TestHardMatchesAbsolutePath(t *testing.T) {
testedConfig := loadConfig("abs_path.yml")

func TestMatchesPatternDirectory(t *testing.T) {
t.Fatal("This test needs to be implemented!")
}
expected := true
realized := testedConfig.ShouldHardDelete("/tmp/2rm/")

func TestMatchesPatternGlobPostfix(t *testing.T) {
t.Fatal("This test needs to be implemented!")
if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}

func TestMatchesPatternGlobPrefix(t *testing.T) {
t.Fatal("This test needs to be implemented!")
}
func TestSoftMatchesAbsolutePath(t *testing.T) {
testedConfig := loadConfig("abs_path.yml")

expected := true
realized := testedConfig.ShouldSoftDelete("/home/john-doe/.local/share/2rm/config.yml")

func TestMatchesAbsolutePath(t *testing.T) {
t.Fatal("This test needs to be implemented!")
if expected != realized {
t.Fatalf("Expected %v but got %v", expected, realized)
}
}
1 change: 0 additions & 1 deletion src/patches/rm_test.go

This file was deleted.

11 changes: 7 additions & 4 deletions src/util/util_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package util
package util_test

import "testing"
import (
"hudson-newey/2rm/src/util"
"testing"
)

func TestInArrayTrue(t *testing.T) {
expectedResult := true
realizedResult := InArray([]int{1, 2, 3}, 1)
realizedResult := util.InArray([]int{1, 2, 3}, 1)

if realizedResult != expectedResult {
t.Fatalf("Expected %v but got %v", expectedResult, realizedResult)
Expand All @@ -13,7 +16,7 @@ func TestInArrayTrue(t *testing.T) {

func TestInArrayFalse(t *testing.T) {
expectedResult := false
realizedResult := InArray([]int{1, 2, 3}, 4)
realizedResult := util.InArray([]int{1, 2, 3}, 4)

if realizedResult != expectedResult {
t.Fatalf("Expected %v but got %v", expectedResult, realizedResult)
Expand Down
4 changes: 4 additions & 0 deletions tests/assets/configs/abs_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hard:
- "/tmp/2rm/"
soft:
- "/home/john-doe/.local/share/2rm/config.yml"
3 changes: 3 additions & 0 deletions tests/assets/configs/only_soft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
soft:
- "*.bak"
- "backups/"

0 comments on commit c7baa97

Please sign in to comment.