From 61b6a5cedc32166aaaa07ca22851d6425a7f65f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Grill?= Date: Sat, 13 Jul 2024 20:42:00 +0200 Subject: [PATCH] more tests not yet covered --- filesystem_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/filesystem_test.go b/filesystem_test.go index 0aa7e3a..b6f16ff 100644 --- a/filesystem_test.go +++ b/filesystem_test.go @@ -310,3 +310,61 @@ func TestChangedOnBackend(t *testing.T) { t.Errorf("expected %v, got %v", data, data2) } } + +func TestDeletedOnBackend(t *testing.T) { + instance := newTestInstance(t) + instance.start() + defer instance.stop() + data := []byte("something") + filename := "test.txt" + err := afero.WriteFile(instance.fs, filename, data, 0x777) + if err != nil { + t.Fatal(err) + } + err = instance.osRemoveFile(filename) + if err != nil { + t.Fatal(err) + } + _, err = instance.fs.Stat(filename) + if err != nil { + if os.IsNotExist(err) { + //ok + return + } + t.Fatal(err) + } else { + t.Error("File exists") + } +} + +func TestUpdatedLocallyWhileOffline(t *testing.T) { + instance := newTestInstance(t) + instance.start() + + data := []byte("something") + filename := "test.txt" + err := instance.osWriteFile(filename, string(data)) + + if err != nil { + t.Fatal(err) + } + + instance.stop() + + data = []byte("somethingelse") + err = instance.osWriteFile(filename, string(data)) + if err != nil { + t.Fatal(err) + } + + instance.start() + + data2, err := afero.ReadFile(instance.fs, filename) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(data, data2) { + t.Errorf("expected %s, got %s", string(data), string(data2)) + } + instance.stop() +}