Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This daemon is a bit valuable in my infrastructure, let's make sure changes don't affect its output.
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*~ | ||
*.pickle | ||
*.line |
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,73 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func readfile(s string) ([]byte, error) { | ||
f, err := os.Open(s) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
blob, err := ioutil.ReadAll(f) | ||
f.Close() | ||
return blob, err | ||
} | ||
|
||
func TestUnMarshal(t *testing.T) { | ||
cmd := exec.Command("testdata/gentests.py") | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
files, err := ioutil.ReadDir(".") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testcases := 0 | ||
for _, file := range files { | ||
if !strings.HasSuffix(file.Name(), ".pickle") { | ||
continue | ||
} | ||
|
||
testcases++ | ||
base := file.Name()[:len(file.Name())-7] | ||
t.Logf("Testing %s", base) | ||
pickle, err := readfile(fmt.Sprintf("%s.pickle", base)) | ||
if err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
blob, err := readfile(fmt.Sprintf("%s.line", base)) | ||
if err != nil { | ||
t.Error(err) | ||
continue | ||
} | ||
lines := strings.Split(string(blob), "\n") | ||
|
||
// Actually run our code | ||
decode := decodePickle(pickle) | ||
|
||
// Validation | ||
for i, s := range decode { | ||
if s != strings.TrimSpace(lines[i]) { | ||
t.Errorf("Graphite line strings don't match: %s != %s", | ||
s, strings.TrimSpace(lines[i])) | ||
} | ||
} | ||
os.Remove(fmt.Sprintf("%s.pickle", base)) | ||
os.Remove(fmt.Sprintf("%s.line", base)) | ||
} | ||
|
||
if testcases == 0 { | ||
t.Fatal("No testcases generated by testdata/gentests.py") | ||
} | ||
} |
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,66 @@ | ||
#!/usr/bin/python | ||
|
||
import pickle | ||
import time | ||
|
||
from types import FloatType | ||
|
||
def ts(): | ||
return time.time() | ||
|
||
data = { | ||
"invalid.000": { "foo": "bar" }, | ||
"invalid.001": [ "string" ], | ||
"invalid.002": [ [ 5, ( ts(), 42 ) ] ], | ||
|
||
"test.001" : [ [ "test.001", [ ts(), 42 ] ], | ||
[ "test.002", [ ts(), 43 ] ], | ||
[ "test.003", ( ts(), 44 ) ], | ||
( "test.004", ( ts(), 45 ) ), | ||
], | ||
|
||
"test.002" : [ [ "test.001", [ str(ts()), 42 ] ], | ||
[ "test.002", [ ts(), "43" ] ], | ||
[ "test.003", ( str(ts()), "44" ) ], | ||
( "test.004", ( str(ts()), "3.14159265358979323846264338327950288419716939937510" ) ), | ||
], | ||
|
||
"test.003" : [ [ "test.001", [ int(ts()), 42 ] ], | ||
[ "test.002", [ int(ts()), 43 ] ], | ||
[ "test.003", ( int(ts()), 44 ) ], | ||
( "test.004", ( int(ts()), 45 ) ), | ||
], | ||
|
||
"test.004" : [ [ "test.001", [ ts(), 42.3456 ] ], | ||
[ "test.002", [ ts(), 3.14159265358979323846 ] ], | ||
[ "test.003", ( ts(), 2.71828 ) ], | ||
( "test.004", ( ts(), -9.7 ) ), | ||
], | ||
|
||
"test.005" : [ [ "test.001", [ ts(), (1<<64) - 1 ] ], | ||
[ "test.002", [ ts(), (1<<64) + 0 ] ], | ||
[ "test.003", ( ts(), (1<<64) + 1 ) ], | ||
( "test.004", ( ts(), (1<<64) + 2 ) ), | ||
], | ||
|
||
} | ||
|
||
if __name__ == "__main__": | ||
for key in data.keys(): | ||
with open("%s.pickle" % key, 'w') as fd: | ||
pickle.dump(data[key], fd) | ||
with open("%s.line" % key, 'w') as fd: | ||
if type(data[key]) != type([]) and type(data[key]) != type(()): | ||
continue | ||
for l in data[key]: | ||
try: | ||
if type(l[1][0]) == FloatType: | ||
l[1][0] = "%.12f" % l[1][0] | ||
if type(l[1][1]) == FloatType: | ||
l[1][1] = "%.12f" % l[1][1] | ||
if type(l[0]) == type(""): | ||
s = "%s %s %s\n" % (l[0], l[1][1], l[1][0]) | ||
fd.write(s) | ||
except: | ||
pass | ||
|