CloudMigration - Display different error messages for create migration errors (#94683)
* start on tokens * more error messages * more handling * rephrased with suggestions from Daniel * separate gms parse method * use translation * refactor initial idea to use error obj * use error dto result * handle gms client * clean logs and comments * fix tests * tests for gms * test and lint * lint * one more handling from gms * typing in fe * use error interface * use validation error * remove unused gms error * use errorlib and helper function in fe * regen api * use same error util * one more error to handle
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/cloudmigration"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -65,3 +66,48 @@ func Test_buildBasePath(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_handleGMSErrors(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c, err := NewGMSClient(&setting.Cfg{
|
||||
CloudMigration: setting.CloudMigrationSettings{
|
||||
GMSDomain: "http://some-domain:8080",
|
||||
},
|
||||
},
|
||||
http.DefaultClient,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
client := c.(*gmsClientImpl)
|
||||
|
||||
testscases := []struct {
|
||||
gmsResBody []byte
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
gmsResBody: []byte(`{"message":"instance is unreachable, make sure the instance is running"}`),
|
||||
expectedError: cloudmigration.ErrInstanceUnreachable,
|
||||
},
|
||||
{
|
||||
gmsResBody: []byte(`{"message":"checking if instance is reachable"}`),
|
||||
expectedError: cloudmigration.ErrInstanceRequestError,
|
||||
},
|
||||
{
|
||||
gmsResBody: []byte(`{"message":"fetching instance by stack id 1234"}`),
|
||||
expectedError: cloudmigration.ErrInstanceRequestError,
|
||||
},
|
||||
{
|
||||
gmsResBody: []byte(`{"status":"error","error":"authentication error: invalid token"}`),
|
||||
expectedError: cloudmigration.ErrTokenValidationFailure,
|
||||
},
|
||||
{
|
||||
gmsResBody: []byte(""),
|
||||
expectedError: cloudmigration.ErrTokenValidationFailure,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testscases {
|
||||
resError := client.handleGMSErrors(tc.gmsResBody)
|
||||
require.ErrorIs(t, resError, tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user