Skip to content

Commit

Permalink
fix unitests
Browse files Browse the repository at this point in the history
  • Loading branch information
omerlavanet committed Dec 8, 2024
1 parent 530a7f1 commit b4afa20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
13 changes: 8 additions & 5 deletions protocol/chainlib/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ func TestGRPCGetSupportedApi(t *testing.T) {
serverApis: map[ApiKey]ApiContainer{{Name: "API1", ConnectionType: connectionType_test}: {api: &spectypes.Api{Name: "API1", Enabled: true}, collectionKey: CollectionKey{ConnectionType: connectionType_test}}},
},
}
_, err = apip.getSupportedApi("API2", connectionType_test)
assert.Error(t, err)
found := strings.Contains(err.Error(), "api not supported")
require.True(t, found)
apiCont, err = apip.getSupportedApi("API2", connectionType_test)
if err == nil {
require.True(t, apiCont.api.Name == "Default-API2")
} else {
found := strings.Contains(err.Error(), "api not supported")
require.True(t, found)
}

// Test case 3: Returns error if the API is disabled
apip = &GrpcChainParser{
Expand All @@ -105,7 +108,7 @@ func TestGRPCGetSupportedApi(t *testing.T) {
}
_, err = apip.getSupportedApi("API1", connectionType_test)
assert.Error(t, err)
found = strings.Contains(err.Error(), "api is disabled")
found := strings.Contains(err.Error(), "api is disabled")
require.True(t, found)
}

Expand Down
8 changes: 6 additions & 2 deletions protocol/chainlib/jsonRPC_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ func TestJSONGetSupportedApi(t *testing.T) {
serverApis: map[ApiKey]ApiContainer{{Name: "API1", ConnectionType: connectionType_test}: {api: &spectypes.Api{Name: "API1", Enabled: true}, collectionKey: CollectionKey{ConnectionType: connectionType_test}}},
},
}
_, err = apip.getSupportedApi("API2", connectionType_test, "")
assert.Error(t, err)
apiCont, err := apip.getSupportedApi("API2", connectionType_test, "")
if err == nil {
require.True(t, apiCont.api.Name == "Default-API2")
} else {
assert.ErrorIs(t, err, common.APINotSupportedError)
}

// Test case 3: Returns error if the API is disabled
apip = &JsonRPCChainParser{
Expand Down
9 changes: 6 additions & 3 deletions protocol/chainlib/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ func TestRestGetSupportedApi(t *testing.T) {
serverApis: map[ApiKey]ApiContainer{{Name: "API1", ConnectionType: connectionType_test}: {api: &spectypes.Api{Name: "API1", Enabled: true}, collectionKey: CollectionKey{ConnectionType: connectionType_test}}},
},
}
_, err = apip.getSupportedApi("API2", connectionType_test)
assert.Error(t, err)
assert.ErrorIs(t, err, common.APINotSupportedError)
apiCont, err := apip.getSupportedApi("API2", connectionType_test)
if err == nil {
require.True(t, apiCont.api.Name == "Default-API2")
} else {
assert.ErrorIs(t, err, common.APINotSupportedError)
}

// Test case 3: Returns error if the API is disabled
apip = &RestChainParser{
Expand Down
9 changes: 7 additions & 2 deletions protocol/chainlib/tendermintRPC_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/lavanet/lava/v4/protocol/chainlib/chainproxy/rpcInterfaceMessages"
"github.com/lavanet/lava/v4/protocol/chainlib/extensionslib"
"github.com/lavanet/lava/v4/protocol/common"
spectypes "github.com/lavanet/lava/v4/x/spec/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -84,8 +85,12 @@ func TestTendermintGetSupportedApi(t *testing.T) {
serverApis: map[ApiKey]ApiContainer{{Name: "API1", ConnectionType: connectionType_test}: {api: &spectypes.Api{Name: "API1", Enabled: true}, collectionKey: CollectionKey{ConnectionType: connectionType_test}}},
},
}
_, err = apip.getSupportedApi("API2", connectionType_test)
assert.Error(t, err)
apiCont, err := apip.getSupportedApi("API2", connectionType_test)
if err == nil {
require.True(t, apiCont.api.Name == "Default-API2")
} else {
assert.ErrorIs(t, err, common.APINotSupportedError)
}

// Test case 3: Returns error if the API is disabled
apip = &TendermintChainParser{
Expand Down

0 comments on commit b4afa20

Please sign in to comment.