-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3618 from Zanadar/test/msfr-test
Tests for mfsr.go
- Loading branch information
Showing
2 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mfsr | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"strconv" | ||
"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 = 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) | ||
} | ||
|
||
fsrepoV := 5 | ||
|
||
rp = testVersionFile(strconv.Itoa(fsrepoV), t) | ||
_, err = rp.Version() | ||
assert.Err(err, t, "Bad VersionFile") | ||
|
||
assert.Nil(rp.WriteVersion(fsrepoV), t, "Trouble writing version") | ||
|
||
assert.Nil(rp.CheckVersion(fsrepoV), t, "Trouble checking the verion") | ||
|
||
assert.Err(rp.CheckVersion(1), t, "Should throw an error for the wrong version.") | ||
} |