-
Notifications
You must be signed in to change notification settings - Fork 23
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
1 parent
103f49d
commit a4120ab
Showing
7 changed files
with
195 additions
and
12 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
package fullnode | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
|
||
cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" | ||
) | ||
|
||
var ( | ||
//go:embed script/download-addrbook.sh | ||
scriptDownloadAddrbook string | ||
) | ||
|
||
const addrbookScriptWrapper = `ls $CONFIG_DIR/addrbook.json 1> /dev/null 2>&1 | ||
ADDRBOOK_EXISTS=$? | ||
if [ $ADDRBOOK_EXISTS -eq 0 ]; then | ||
echo "Address book already exists" | ||
exit 0 | ||
fi | ||
ls -l $CONFIG_DIR/addrbook.json | ||
%s | ||
ls -l $CONFIG_DIR/addrbook.json | ||
echo "Address book $ADDRBOOK_FILE downloaded" | ||
` | ||
|
||
// DownloadGenesisCommand returns a proper address book command for use in an init container. | ||
func DownloadAddrbookCommand(cfg cosmosv1.ChainSpec) (string, []string) { | ||
args := []string{"-c"} | ||
switch { | ||
case cfg.AddrbookScript != nil: | ||
args = append(args, fmt.Sprintf(addrbookScriptWrapper, *cfg.AddrbookScript)) | ||
case cfg.AddrbookURL != nil: | ||
args = append(args, fmt.Sprintf(addrbookScriptWrapper, scriptDownloadAddrbook), "-s", *cfg.AddrbookURL) | ||
default: | ||
args = append(args, "echo Using default address book") | ||
} | ||
return "sh", args | ||
} |
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,72 @@ | ||
package fullnode | ||
|
||
import ( | ||
"testing" | ||
|
||
cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDownloadAddrbookCommand(t *testing.T) { | ||
t.Parallel() | ||
|
||
requireValidScript := func(t *testing.T, script string) { | ||
t.Helper() | ||
require.NotEmpty(t, script) | ||
require.Contains(t, script, `if [ $ADDRBOOK_EXISTS -eq 0 ]`) | ||
} | ||
|
||
t.Run("default", func(t *testing.T) { | ||
var cfg cosmosv1.ChainSpec | ||
|
||
cmd, args := DownloadAddrbookCommand(cfg) | ||
require.Equal(t, "sh", cmd) | ||
|
||
require.Len(t, args, 2) | ||
|
||
require.Equal(t, "-c", args[0]) | ||
|
||
got := args[1] | ||
require.NotContains(t, got, "ADDRBOOK_EXISTS") | ||
require.Contains(t, got, "Using default address book") | ||
}) | ||
|
||
t.Run("download", func(t *testing.T) { | ||
cfg := cosmosv1.ChainSpec{ | ||
AddrbookURL: ptr("https://example.com/addrbook.json"), | ||
} | ||
cmd, args := DownloadAddrbookCommand(cfg) | ||
require.Equal(t, "sh", cmd) | ||
|
||
require.Len(t, args, 4) | ||
|
||
require.Equal(t, "-c", args[0]) | ||
got := args[1] | ||
requireValidScript(t, got) | ||
require.Contains(t, got, `ADDRBOOK_URL`) | ||
require.Contains(t, got, "download_json") | ||
|
||
require.Equal(t, "-s", args[2]) | ||
require.Equal(t, "https://example.com/addrbook.json", args[3]) | ||
}) | ||
|
||
t.Run("custom", func(t *testing.T) { | ||
cfg := cosmosv1.ChainSpec{ | ||
// Keeping this to assert that custom script takes precedence. | ||
AddrbookURL: ptr("https://example.com/addrbook.json"), | ||
AddrbookScript: ptr("echo hi"), | ||
} | ||
cmd, args := DownloadAddrbookCommand(cfg) | ||
require.Equal(t, "sh", cmd) | ||
|
||
require.Len(t, args, 2) | ||
|
||
require.Equal(t, "-c", args[0]) | ||
|
||
got := args[1] | ||
requireValidScript(t, got) | ||
|
||
require.NotContains(t, got, "ADDRBOOK_URL") | ||
require.Contains(t, got, "echo hi") | ||
}) | ||
} |
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