mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 23:17:55 +02:00
Augment IsOfflineError(err) so that it detects if the hishtory server is down, and will then treat all API errors as offline errors
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
"github.com/ddworken/hishtory/client/hctx"
|
||||
"github.com/ddworken/hishtory/shared"
|
||||
"github.com/ddworken/hishtory/shared/testutils"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
@ -355,3 +357,16 @@ func TestSplitEscaped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAugmentedIsOfflineError(t *testing.T) {
|
||||
defer testutils.BackupAndRestoreEnv("HISHTORY_SIMULATE_NETWORK_ERROR")()
|
||||
|
||||
// By default, when the hishtory server is up, then IsOfflineError checks the error msg
|
||||
require.True(t, isHishtoryServerUp())
|
||||
require.False(t, IsOfflineError(fmt.Errorf("unchecked error type")))
|
||||
|
||||
// When the hishtory server is down, then all error messages are treated as being due to offline errors
|
||||
os.Setenv("HISHTORY_SIMULATE_NETWORK_ERROR", "1")
|
||||
require.False(t, isHishtoryServerUp())
|
||||
require.True(t, IsOfflineError(fmt.Errorf("unchecked error type")))
|
||||
}
|
||||
|
Reference in New Issue
Block a user