mirror of
https://github.com/aljazceru/nigiri.git
synced 2025-12-30 20:54:36 +01:00
Changes for new version of esplora image (#62)
* changes for new version of esplora image * add electrs port and esplora url env vars in compose yaml files * wrap viper methods into Config type and use constants package * add controller to interact with nigiri resources: * .env for docker-compose * docker daemon * json config file * add use of constants and config packages and change start flag from --port to --env * add package for global constants and variables * add use of controller and constants packages instead of local methods and vars * bump version * use contants in logs command tests
This commit is contained in:
committed by
Marco Argentieri
parent
d0b3676c14
commit
e02c2fdd0d
159
cli/controller/parser_test.go
Normal file
159
cli/controller/parser_test.go
Normal file
@@ -0,0 +1,159 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/vulpemventures/nigiri/cli/constants"
|
||||
)
|
||||
|
||||
func TestParserParseNetwork(t *testing.T) {
|
||||
p := &Parser{}
|
||||
|
||||
validNetworks := []string{"regtest"}
|
||||
for _, n := range validNetworks {
|
||||
err := p.parseNetwork(n)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserParseDatadir(t *testing.T) {
|
||||
p := &Parser{}
|
||||
|
||||
currentDir, _ := os.Getwd()
|
||||
validDatadirs := []string{currentDir}
|
||||
for _, n := range validDatadirs {
|
||||
err := p.parseDatadir(n)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserParseEnvJSON(t *testing.T) {
|
||||
p := &Parser{}
|
||||
|
||||
for _, e := range testJSONs {
|
||||
parsedJSON, _ := json.Marshal(e)
|
||||
mergedJSON, err := p.parseEnvJSON(string(parsedJSON))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(mergedJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserParseNetworkShouldFail(t *testing.T) {
|
||||
p := &Parser{}
|
||||
|
||||
invalidNetworks := []string{"simnet", "testnet"}
|
||||
for _, n := range invalidNetworks {
|
||||
err := p.parseNetwork(n)
|
||||
if err == nil {
|
||||
t.Fatalf("Should have been failed before")
|
||||
}
|
||||
if err != constants.ErrInvalidNetwork {
|
||||
t.Fatalf("Got: %s, wanted: %s", err, constants.ErrInvalidNetwork)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserParseDatadirShouldFail(t *testing.T) {
|
||||
p := &Parser{}
|
||||
|
||||
invalidDatadirs := []string{"."}
|
||||
for _, d := range invalidDatadirs {
|
||||
err := p.parseDatadir(d)
|
||||
if err == nil {
|
||||
t.Fatalf("Should have been failed before")
|
||||
}
|
||||
if err != constants.ErrInvalidDatadir {
|
||||
t.Fatalf("Got: %s, wanted: %s", err, constants.ErrInvalidDatadir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testJSONs = []map[string]interface{}{
|
||||
// only btc services
|
||||
{
|
||||
"urls": map[string]string{
|
||||
"bitcoin_esplora": "https://blockstream.info/",
|
||||
},
|
||||
"ports": map[string]map[string]int{
|
||||
"bitcoin": map[string]int{
|
||||
"node": 1111,
|
||||
"esplora": 2222,
|
||||
"electrs": 3333,
|
||||
"chopsticks": 4444,
|
||||
},
|
||||
},
|
||||
},
|
||||
// btc and liquid services
|
||||
{
|
||||
"urls": map[string]string{
|
||||
"bitcoin_esplora": "https://blockstream.info/",
|
||||
"liquid_esplora": "http://blockstream.info/liquid",
|
||||
},
|
||||
"ports": map[string]map[string]int{
|
||||
"bitcoin": map[string]int{
|
||||
"node": 1111,
|
||||
"esplora": 2222,
|
||||
"electrs": 3333,
|
||||
"chopsticks": 4444,
|
||||
},
|
||||
"liquid": map[string]int{
|
||||
"node": 5555,
|
||||
"esplora": 6666,
|
||||
"electrs": 7777,
|
||||
"chopsticks": 8888,
|
||||
},
|
||||
},
|
||||
},
|
||||
// incomplete examples:
|
||||
// incomplete bitcoin services
|
||||
{
|
||||
"ports": map[string]map[string]int{
|
||||
"bitcoin": map[string]int{
|
||||
"esplora": 1111,
|
||||
"electrs": 2222,
|
||||
"chopsticks": 3333,
|
||||
},
|
||||
},
|
||||
"urls": map[string]string{
|
||||
"bitcoin_esplora": "http://test.com/api",
|
||||
},
|
||||
},
|
||||
// bitcoin services ports and liquid service url
|
||||
{
|
||||
"ports": map[string]map[string]int{
|
||||
"bitcoin": map[string]int{
|
||||
"node": 1111,
|
||||
"esplora": 2222,
|
||||
"electrs": 3333,
|
||||
"chopsticks": 4444,
|
||||
},
|
||||
},
|
||||
"urls": map[string]string{
|
||||
"liquid_esplora": "http://test.com/liquid/api",
|
||||
},
|
||||
},
|
||||
// liquid services ports and bitcoin service url
|
||||
{
|
||||
"ports": map[string]map[string]int{
|
||||
"liquid": map[string]int{
|
||||
"node": 1111,
|
||||
"esplora": 2222,
|
||||
"electrs": 3333,
|
||||
"chopsticks": 4444,
|
||||
},
|
||||
},
|
||||
"urls": map[string]string{
|
||||
"bitcoin_esplora": "http://test.com/api",
|
||||
},
|
||||
},
|
||||
// empty config
|
||||
{},
|
||||
}
|
||||
Reference in New Issue
Block a user