From eb5ba9d7618f23277b45fa8de7189602ace1c608 Mon Sep 17 00:00:00 2001 From: Zander Mackie Date: Fri, 20 Jan 2017 15:58:55 -0500 Subject: [PATCH 1/4] Tests for msfr License: MIT Signed-off-by: Zander Mackie --- repo/fsrepo/migrations/mfsr_test.go | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 repo/fsrepo/migrations/mfsr_test.go diff --git a/repo/fsrepo/migrations/mfsr_test.go b/repo/fsrepo/migrations/mfsr_test.go new file mode 100644 index 00000000000..2daf093c43f --- /dev/null +++ b/repo/fsrepo/migrations/mfsr_test.go @@ -0,0 +1,33 @@ +package mfsr + +import ( + "io/ioutil" + "testing" + + "github.com/ipfs/go-ipfs/thirdparty/assert" +) + +func testVersionFile(v string, t *testing.T) (rp RepoPath) { + name, err := ioutil.TempDir("", v) + if err != nil { + t.Fatal(err) + } + rp = RepoPath(name) + return rp +} + +func TestVersion(t *testing.T) { + rp := RepoPath("") + _, err := rp.Version() + assert.Err(err, t, "Should throw an error when path is bad,") + + rp = testVersionFile("4", t) + _, err = rp.Version() + assert.Err(err, t, "Bad VersionFile") + + assert.Nil(rp.WriteVersion(4), t, "Trouble writing version") + + assert.Nil(rp.CheckVersion(4), t, "Trouble checking the verion") + + assert.Err(rp.CheckVersion(1), t, "Should throw an error for the wrong version.") +} From 86c1fb8c965392e7a4ca872bd7b3750307b18925 Mon Sep 17 00:00:00 2001 From: Zander Mackie Date: Fri, 20 Jan 2017 16:01:14 -0500 Subject: [PATCH 2/4] msfr shouldn't swallow os.IsNotExist - fsrepo calls and checks for this error (`fsrepo.go:140`) License: MIT Signed-off-by: Zander Mackie --- repo/fsrepo/migrations/mfsr.go | 10 ++-------- repo/fsrepo/migrations/mfsr_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/repo/fsrepo/migrations/mfsr.go b/repo/fsrepo/migrations/mfsr.go index 3e9329f17ca..64f6733a0a4 100644 --- a/repo/fsrepo/migrations/mfsr.go +++ b/repo/fsrepo/migrations/mfsr.go @@ -23,8 +23,8 @@ func (rp RepoPath) Version() (int, error) { } fn := rp.VersionFile() - if _, err := os.Stat(fn); os.IsNotExist(err) { - return 0, VersionFileNotFound(rp) + if _, err := os.Stat(fn); err != nil { + return 0, err } c, err := ioutil.ReadFile(fn) @@ -53,9 +53,3 @@ func (rp RepoPath) WriteVersion(version int) error { fn := rp.VersionFile() return ioutil.WriteFile(fn, []byte(fmt.Sprintf("%d\n", version)), 0644) } - -type VersionFileNotFound string - -func (v VersionFileNotFound) Error() string { - return "no version file in repo at " + string(v) -} diff --git a/repo/fsrepo/migrations/mfsr_test.go b/repo/fsrepo/migrations/mfsr_test.go index 2daf093c43f..4b1a941d1d7 100644 --- a/repo/fsrepo/migrations/mfsr_test.go +++ b/repo/fsrepo/migrations/mfsr_test.go @@ -2,6 +2,7 @@ package mfsr import ( "io/ioutil" + "os" "testing" "github.com/ipfs/go-ipfs/thirdparty/assert" @@ -21,6 +22,12 @@ func TestVersion(t *testing.T) { _, err := rp.Version() assert.Err(err, t, "Should throw an error when path is bad,") + rp = RepoPath("/path/to/nowhere") + _, err = rp.Version() + if !os.IsNotExist(err) { + t.Fatalf("Should throw an `IsNotExist` error when file doesn't exist: %v", err) + } + rp = testVersionFile("4", t) _, err = rp.Version() assert.Err(err, t, "Bad VersionFile") From fef5d5bbbdc5cc72ff32630d114908b58fbd5d58 Mon Sep 17 00:00:00 2001 From: Zander Mackie Date: Fri, 20 Jan 2017 16:02:31 -0500 Subject: [PATCH 3/4] Cleanup go vet error License: MIT Signed-off-by: Zander Mackie --- repo/fsrepo/migrations/mfsr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo/fsrepo/migrations/mfsr.go b/repo/fsrepo/migrations/mfsr.go index 64f6733a0a4..c0f3b8b4862 100644 --- a/repo/fsrepo/migrations/mfsr.go +++ b/repo/fsrepo/migrations/mfsr.go @@ -43,7 +43,7 @@ func (rp RepoPath) CheckVersion(version int) error { } if v != version { - return fmt.Errorf("versions differ (expected: %s, actual:%s)", version, v) + return fmt.Errorf("versions differ (expected: %d, actual:%d)", version, v) } return nil From 310c08cf58eef25fbda468fb1db97612b396bef6 Mon Sep 17 00:00:00 2001 From: Zander Mackie Date: Fri, 20 Jan 2017 17:27:17 -0500 Subject: [PATCH 4/4] Update Version to reflect fsrepo change License: MIT Signed-off-by: Zander Mackie --- repo/fsrepo/migrations/mfsr_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/repo/fsrepo/migrations/mfsr_test.go b/repo/fsrepo/migrations/mfsr_test.go index 4b1a941d1d7..0f66f71ce28 100644 --- a/repo/fsrepo/migrations/mfsr_test.go +++ b/repo/fsrepo/migrations/mfsr_test.go @@ -3,6 +3,7 @@ package mfsr import ( "io/ioutil" "os" + "strconv" "testing" "github.com/ipfs/go-ipfs/thirdparty/assert" @@ -28,13 +29,15 @@ func TestVersion(t *testing.T) { t.Fatalf("Should throw an `IsNotExist` error when file doesn't exist: %v", err) } - rp = testVersionFile("4", t) + fsrepoV := 5 + + rp = testVersionFile(strconv.Itoa(fsrepoV), t) _, err = rp.Version() assert.Err(err, t, "Bad VersionFile") - assert.Nil(rp.WriteVersion(4), t, "Trouble writing version") + assert.Nil(rp.WriteVersion(fsrepoV), t, "Trouble writing version") - assert.Nil(rp.CheckVersion(4), t, "Trouble checking the verion") + assert.Nil(rp.CheckVersion(fsrepoV), t, "Trouble checking the verion") assert.Err(rp.CheckVersion(1), t, "Should throw an error for the wrong version.") }