Initial commit
This commit is contained in:
65
taskwarrior/taskwarrior_test.go
Normal file
65
taskwarrior/taskwarrior_test.go
Normal file
@ -0,0 +1,65 @@
|
||||
package taskwarrior
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TaskWarriorTestSetup(dir string) {
|
||||
// Create a taskrc file
|
||||
taskrc := fmt.Sprintf("%s/taskrc", dir)
|
||||
taskrcContents := fmt.Sprintf("data.location=%s\n", dir)
|
||||
os.WriteFile(taskrc, []byte(taskrcContents), 0644)
|
||||
}
|
||||
|
||||
func TestTaskSquire_GetContext(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
fmt.Printf("dir: %s", dir)
|
||||
TaskWarriorTestSetup(dir)
|
||||
|
||||
type fields struct {
|
||||
configLocation string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
prep func()
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "Test without context",
|
||||
fields: fields{
|
||||
configLocation: fmt.Sprintf("%s/taskrc", dir),
|
||||
},
|
||||
prep: func() {},
|
||||
want: "none",
|
||||
},
|
||||
{
|
||||
name: "Test with context",
|
||||
fields: fields{
|
||||
configLocation: fmt.Sprintf("%s/taskrc", dir),
|
||||
},
|
||||
prep: func() {
|
||||
f, err := os.OpenFile(fmt.Sprintf("%s/taskrc", dir), os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to open file: %s", err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.Write([]byte("context=test\ncontext.test.read=+test\ncontext.test.write=+test")); err != nil {
|
||||
t.Error("Failed to write to file")
|
||||
}
|
||||
},
|
||||
want: "test",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.prep()
|
||||
ts := NewTaskSquire(tt.fields.configLocation)
|
||||
if got := ts.GetActiveContext(); got.Name != tt.want {
|
||||
t.Errorf("TaskSquire.GetContext() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user