Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use testify for more succinct tests #247

Merged
merged 7 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move fs/ tests to testify
  • Loading branch information
jstaf committed Mar 4, 2022
commit a1430c64ce51eaba3904351eb4590bae301165ef
35 changes: 12 additions & 23 deletions fs/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@ package fs

import (
"fmt"
"log"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRootGet(t *testing.T) {
t.Parallel()
cache := NewFilesystem(auth, "test_root_get.db")
root, err := cache.GetPath("/", auth)
if err != nil {
t.Fatal(err)
}

if root.Path() != "/" {
t.Fatal("Root path did not resolve correctly")
}
require.NoError(t, err)
assert.Equal(t, "/", root.Path(), "Root path did not resolve correctly.")
}

func TestRootChildrenUpdate(t *testing.T) {
t.Parallel()
cache := NewFilesystem(auth, "test_root_children_update.db")
children, err := cache.GetChildrenPath("/", auth)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

if _, exists := children["documents"]; !exists {
t.Fatal("Could not find documents folder.")
Expand All @@ -37,23 +32,19 @@ func TestSubdirGet(t *testing.T) {
t.Parallel()
cache := NewFilesystem(auth, "test_subdir_get.db")
documents, err := cache.GetPath("/Documents", auth)
if err != nil {
t.Fatal(err)
}
if documents.Name() != "Documents" {
t.Fatalf("Failed to fetch \"/Documents\". Got \"%s\" instead!\n", documents.Name())
}
require.NoError(t, err)
assert.Equal(t, "Documents", documents.Name(), "Failed to fetch \"/Documents\".")
}

func TestSubdirChildrenUpdate(t *testing.T) {
t.Parallel()
cache := NewFilesystem(auth, "test_subdir_children_update.db")
children, err := cache.GetChildrenPath("/Documents", auth)
failOnErr(t, err)
require.NoError(t, err)

if _, exists := children["documents"]; exists {
log.Println("Documents directory found inside itself. " +
"Likely the cache did not traverse correctly.\n\nChildren:\n")
fmt.Println("Documents directory found inside itself. " +
"Likely the cache did not traverse correctly.\n\nChildren:")
for key := range children {
fmt.Println(key)
}
Expand All @@ -69,7 +60,5 @@ func TestSamePointer(t *testing.T) {
if item != item2 {
t.Fatalf("Pointers to cached items do not match: %p != %p\n", item, item2)
}
if item == nil {
t.Fatal("Item was nil!")
}
assert.NotNil(t, item)
}
Loading