mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-11 23:29:48 +08:00
34 lines
871 B
Go
34 lines
871 B
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadImportedConnectionConfigFileRejectsOversizedFiles(t *testing.T) {
|
|
for _, ext := range []string{connectionPackageExtension, ".json"} {
|
|
t.Run(ext, func(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "connections"+ext)
|
|
|
|
file, err := os.Create(path)
|
|
if err != nil {
|
|
t.Fatalf("Create returned error: %v", err)
|
|
}
|
|
if err := file.Truncate(connectionImportMaxFileBytes + 1); err != nil {
|
|
file.Close()
|
|
t.Fatalf("Truncate returned error: %v", err)
|
|
}
|
|
if err := file.Close(); err != nil {
|
|
t.Fatalf("Close returned error: %v", err)
|
|
}
|
|
|
|
_, err = readImportedConnectionConfigFile(path)
|
|
if !errors.Is(err, errConnectionImportFileTooLarge) {
|
|
t.Fatalf("oversized import file should return errConnectionImportFileTooLarge, got: %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|