getPeerStatus() helper- required for `peer show` command.

This commit is contained in:
Netscape Navigator 2020-09-14 08:11:02 -05:00
parent bf6ef1d07c
commit a91803a2bd
4 changed files with 57 additions and 5 deletions

View File

@ -20,7 +20,12 @@ You can override this value by specifying a `PIGEON_PATH` ENV var.
|Done?|Verb |Noun | Flag / arg 1 | Flag 2 |
|-----|------------|--------|---------------|-----------|
| |follow |peer | user mhash | |
| |show |peers | | |
| |show |peers | --blocked | |
| |block |peer | user mhash | |
| |unblock |peer | user mhash | |
| |unfollow |peer | | |
| |create |blob | file path | |
| |create |blob | pipe | |
| |create |bundle | | |
@ -28,15 +33,10 @@ You can override this value by specifying a `PIGEON_PATH` ENV var.
| |find |blob | | |
| |find |message | --all | |
| |find |message | --last | |
| |follow |peer | user mhash | |
| |ingest |bundle | | |
| |publish |draft | | |
| |show |draft | | |
| |show |message | message mhash | |
| |show |peers | | |
| |show |peers | --blocked | |
| |unblock |peer | user mhash | |
| |unfollow |peer | | |
| |update |draft | --key=? | --value=? |
| X |show |identity| | |
| X |create |identity| | |

0
coverage.sh Normal file → Executable file
View File

36
project/peers.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"database/sql"
"log"
)
type peerStatus string
const (
following peerStatus = "following"
blocked = "blocked"
unknown = "unknown"
)
func getPeerStatus(mHash string) peerStatus {
sqlStatement := `SELECT status FROM users WHERE mhash=$1;`
var status peerStatus
row := Database.QueryRow(sqlStatement, mHash)
switch err := row.Scan(&status); err {
case sql.ErrNoRows:
return "unknown"
case nil:
return status
default:
log.Fatalf("getPeerStatus failure: %s", err)
panic(err)
}
}
// func followPeer() {}
// func showPeers() {}
// func showBlockedPeers() {}
// func blockPeer() {}
// func unblockPeer() {}
// func unfollowPeer() {}

16
project/peers_test.go Normal file
View File

@ -0,0 +1,16 @@
package main
import (
"testing"
)
// TEST CASE: Attempting to getPeerStatus() of peer that
// does not exist.
func TestGetPeerStatus(t *testing.T) {
resetDB()
mHash := "USER.RJFSFK8YZ8XGTGKQDMSQCQPQXKH8GPRCDY86YZCFQ1QRKYEF48MG"
status := getPeerStatus(mHash)
if status != peerStatus("unknown") {
t.Fatalf("Expected `unknown`, got %s", status)
}
}