cheat/internal/cheatpath/writeable_test.go
cuibuwei 41b6238234 chore: fix function names in comment
Signed-off-by: cuibuwei <cuibuwei@gmail.com>
2024-04-13 16:36:00 +08:00

51 lines
1.2 KiB
Go

package cheatpath
import (
"testing"
)
// TestWriteableOK asserts that Writeable returns the appropriate cheatpath
// when a writeable cheatpath exists
func TestWriteableOK(t *testing.T) {
// initialize some cheatpaths
cheatpaths := []Cheatpath{
Cheatpath{Path: "/foo", ReadOnly: true},
Cheatpath{Path: "/bar", ReadOnly: false},
Cheatpath{Path: "/baz", ReadOnly: true},
}
// get the writeable cheatpath
got, err := Writeable(cheatpaths)
// assert that no errors were returned
if err != nil {
t.Errorf("failed to get cheatpath: %v", err)
}
// assert that the path is correct
if got.Path != "/bar" {
t.Errorf("incorrect cheatpath returned: got: %s", got.Path)
}
}
// TestWriteableNotOK asserts that Writeable returns an error when no writeable
// cheatpaths exist
func TestWriteableNotOK(t *testing.T) {
// initialize some cheatpaths
cheatpaths := []Cheatpath{
Cheatpath{Path: "/foo", ReadOnly: true},
Cheatpath{Path: "/bar", ReadOnly: true},
Cheatpath{Path: "/baz", ReadOnly: true},
}
// get the writeable cheatpath
_, err := Writeable(cheatpaths)
// assert that no errors were returned
if err == nil {
t.Errorf("failed to return an error when no writeable paths found")
}
}