-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
135 additions
and
53 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
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,65 @@ | ||
package file | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReadTOML(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
a := struct { | ||
Text string `toml:"text"` | ||
}{} | ||
|
||
err := ReadTOML("testfiles/donoexists", &a) | ||
assert.Error(err, "could find file ^^") | ||
|
||
err = ReadTOML("testfiles/trash.txt", &a) | ||
assert.Error(err, "could marshel file ^^") | ||
|
||
err = ReadTOML("testfiles/ok.toml", &a) | ||
assert.NoError(err) | ||
assert.Equal("hallo", a.Text) | ||
} | ||
|
||
func TestReadJSON(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
a := struct { | ||
Text string `toml:"text"` | ||
}{} | ||
|
||
err := ReadJSON("testfiles/donoexists", &a) | ||
assert.Error(err, "could find file ^^") | ||
|
||
err = ReadJSON("testfiles/trash.txt", &a) | ||
assert.Error(err, "could marshel file ^^") | ||
|
||
err = ReadJSON("testfiles/ok.json", &a) | ||
assert.NoError(err) | ||
assert.Equal("hallo", a.Text) | ||
} | ||
|
||
func TestSaveJSON(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tmpfile, _ := ioutil.TempFile("/tmp", "lib-json-testfile.json") | ||
err := SaveJSON(tmpfile.Name(), 3) | ||
assert.NoError(err, "could not save temp") | ||
|
||
err = SaveJSON(tmpfile.Name(), tmpfile.Name) | ||
assert.Error(err, "could not save func") | ||
|
||
err = SaveJSON("/dev/null", 4) | ||
assert.Error(err, "could not save to /dev/null") | ||
|
||
var testvalue int | ||
err = ReadJSON(tmpfile.Name(), &testvalue) | ||
assert.NoError(err) | ||
assert.Equal(3, testvalue) | ||
os.Remove(tmpfile.Name()) | ||
} |
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,3 @@ | ||
{ | ||
"text": "hallo" | ||
} |
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 @@ | ||
text = "hallo" |
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 @@ | ||
wrong format example |
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,27 @@ | ||
package file | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSaveJSONWorker(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tmpfile, _ := ioutil.TempFile("/tmp", "lib-json-workertest.json") | ||
|
||
worker := NewSaveJSONWorker(100*time.Millisecond, tmpfile.Name(), 12) | ||
assert.NotNil(worker) | ||
|
||
time.Sleep(300 * time.Millisecond) | ||
|
||
var testvalue int | ||
err := ReadJSON(tmpfile.Name(), &testvalue) | ||
assert.NoError(err) | ||
assert.Equal(12, testvalue) | ||
os.Remove(tmpfile.Name()) | ||
} |
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
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
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