5
0
mirror of https://github.com/cwinfo/hyperboria-peers.git synced 2024-11-22 03:40:27 +00:00

Merge pull request #19 from hyperboria/travis

Add basic tests
This commit is contained in:
ansuz 2015-11-25 16:51:29 -05:00
commit 403bb4dcf2
5 changed files with 49 additions and 8 deletions

6
.travis.yml Normal file
View File

@ -0,0 +1,6 @@
sudo: false
addons:
apt:
packages:
- python3
script: ./tests.py

View File

@ -2,6 +2,5 @@
"password":"public-20150903-6pb6aEKDDKVr9zsBJIyDUYfrXYzQv1",
"publicKey":"s680fh7g69ww3y9cmrxt910u5hvrwrmcnln1sz6mq1jk5mquq8k0.k",
"user":"katt",
"contact":"oniichan@mrowr.me",
"contact":"oniichan@mrowr.me"
}

View File

@ -2,6 +2,5 @@
"password":"ALcVwciz1enkZTE1SvBjj7WX2gZwtcTa",
"publicKey":"bddc5j6sc45hlrdnccu120zwnmm2z0qlbfkxn9n8xbs0vqgx9fh0.k",
"user":"ansuz",
"contact":"ansuz@transitiontech.ca",
"contact":"ansuz@transitiontech.ca"
}

View File

@ -7,7 +7,7 @@ If you've created a public node, and would like to have it listed here, fork the
## Nodeinfo.json
This repository is meant to extend the [nodeinfo.json standard](https://github.com/hyperboria/docs/blob/master/cjdns/nodeinfo-json.md "nodeinfo.json standard, from Hyperboria's docs repo").
This repository is meant to extend the [nodeinfo.json standard](https://github.com/hyperboria/docs/blob/master/cjdns/nodeinfo-json.md "nodeinfo.json standard, from Hyperboria's docs repo").
`nodeinfo.json` is a valid [JSON](http://www.json.org/ "the Javascript Object Notation standard") file hosted on a webserver's root which displays information about that node:
* services it hosts
@ -65,10 +65,7 @@ By following this scheme, we make it possible for users to programmatically find
```
> Note: the snippet above is **not valid json**. It would need to be wrapped in an additional block of curly braces `{ }`
>
> We will create a linter that validates such blocks (coming soon).
## Naming your entry
You can name your file whatever you want, but for simplicity's sake, avoid characters which will need to be escaped at the command line.

40
tests.py Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
import json
import os
import sys
REQUIRED_FIELDS = ['publicKey', 'password', 'contact']
RED = '\x1b[01;31m'
GREEN = '\x1b[01;32m'
END = '\x1b[0m'
def validate(path):
print("Validating %s" % path)
try:
creds = open(path).read()
peers = json.loads("{%s}" % creds)
hosts = peers.keys()
for host in hosts:
for field in REQUIRED_FIELDS:
if not field in peers[host]:
print(" %sHost %s is missing the %s field!%s" % (RED, host, field, END))
return False
print(" %sSuccess!%s" % (GREEN, END))
return True
except ValueError:
print(" %sInvalid JSON!%s" % (RED, END))
return False
success = True
for directory, subdirs, files in os.walk('.'):
if len(files) > 0:
for f in files:
if f.endswith('.k'):
result = validate("%s/%s" % (directory, f))
if not result:
success = False
if not success:
sys.exit(1)