Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Jul 10, 2023
1 parent 341e789 commit 9aa7849
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_createCaptiveCoreDefaultNetworkConfig(t *testing.T) {
func Test_createCaptiveCoreDefaultConfig(t *testing.T) {

var errorMsgDefaultConfig = "error generating default captive core config. invalid config: %s not allowed with %s network"
var errorMsgConfig = "error generating captive core config. %s must be set"
var errorMsgDefaultConfig = "invalid config: %s not allowed with %s network"
tests := []struct {
name string
config Config
Expand Down Expand Up @@ -66,9 +65,33 @@ func Test_createCaptiveCoreDefaultNetworkConfig(t *testing.T) {
NetworkPassphrase: "",
HistoryArchiveURLs: []string{},
},
errStr: fmt.Sprintf("error generating default captive core config. " +
"no default configuration found for network unknown"),
errStr: "no default configuration found for network unknown",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := createCaptiveCoreDefaultConfig(&tt.config)
if tt.errStr == "" {
assert.NoError(t, e)
assert.Equal(t, tt.networkPassphrase, tt.config.NetworkPassphrase)
assert.Equal(t, tt.historyArchiveURLs, tt.config.HistoryArchiveURLs)
} else {
assert.Equal(t, tt.errStr, e.Error())
}
})
}
}

func Test_createCaptiveCoreConfig(t *testing.T) {

var errorMsgConfig = "%s must be set"
tests := []struct {
name string
config Config
networkPassphrase string
historyArchiveURLs []string
errStr string
}{
{
name: "no network specified",
config: Config{
Expand All @@ -95,7 +118,7 @@ func Test_createCaptiveCoreDefaultNetworkConfig(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := setCaptiveCoreConfiguration(&tt.config)
e := createCaptiveCoreConfig(&tt.config)
if tt.errStr == "" {
assert.NoError(t, e)
assert.Equal(t, tt.networkPassphrase, tt.config.NetworkPassphrase)
Expand Down

0 comments on commit 9aa7849

Please sign in to comment.