From fb080cd12e64b3b619aaa4df84da063dafe969a3 Mon Sep 17 00:00:00 2001 From: Vee Zhang Date: Thu, 7 Sep 2023 18:03:11 +0800 Subject: [PATCH] fix: crash with unset source --- README.md | 2 +- pkg/errors/errors.go | 1 + pkg/source/source.go | 5 ++++- pkg/source/source_test.go | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0da5de9c..04f5fe7c 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,7 @@ tags: - name: Person id: type: "STRING" - concatItems: 0 + concatItems: - "abc" - 1 function: hash diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 5397c905..c0b5481b 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -8,6 +8,7 @@ var ( ErrUnsupportedClientVersion = stderrors.New("unsupported client version") ErrNoAddresses = stderrors.New("no addresses") ErrInvalidAddress = stderrors.New("invalid address") + ErrUnsetSource = stderrors.New("unset source") ErrInvalidIndex = stderrors.New("invalid index") ErrNoSpaceName = stderrors.New("no space name") ErrNoGraphName = stderrors.New("no graph name") diff --git a/pkg/source/source.go b/pkg/source/source.go index 76cbe4fa..f2955c89 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -3,6 +3,8 @@ package source import ( "io" + + "github.com/vesoft-inc/nebula-importer/v4/pkg/errors" ) type ( @@ -39,7 +41,8 @@ func New(c *Config) (Source, error) { return newHDFSSource(c), nil case c.GCS != nil: return newGCSSource(c), nil - default: + case c.Local != nil: return newLocalSource(c), nil } + return nil, errors.ErrUnsetSource } diff --git a/pkg/source/source_test.go b/pkg/source/source_test.go index d84550c3..9e362b98 100644 --- a/pkg/source/source_test.go +++ b/pkg/source/source_test.go @@ -3,9 +3,18 @@ package source import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/vesoft-inc/nebula-importer/v4/pkg/errors" ) var _ = Describe("Source", func() { + It("ErrNoSource", func() { + c := Config{} + s, err := New(&c) + Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(errors.ErrUnsetSource)) + Expect(s).To(BeNil()) + }) + It("S3", func() { c := Config{ S3: &S3Config{