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:
David Dworken
2023-09-23 16:40:03 -07:00
parent bd03f90b0b
commit 8443292070
4 changed files with 35 additions and 2 deletions

View File

@ -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")))
}