|
| 1 | +package util_test |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo/v2" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + |
| 7 | + "github.com/devstream-io/devstream/internal/pkg/configmanager" |
| 8 | + "github.com/devstream-io/devstream/internal/pkg/plugin/installer/util" |
| 9 | + "github.com/devstream-io/devstream/pkg/util/scm/git" |
| 10 | +) |
| 11 | + |
| 12 | +var _ = Describe("DecodePlugin func", func() { |
| 13 | + var ( |
| 14 | + plugData *mockStruct |
| 15 | + rawData configmanager.RawOptions |
| 16 | + ) |
| 17 | + When("decoder is not valid", func() { |
| 18 | + BeforeEach(func() { |
| 19 | + plugData = nil |
| 20 | + }) |
| 21 | + It("should return error", func() { |
| 22 | + err := util.DecodePlugin(rawData, plugData) |
| 23 | + Expect(err).Should(HaveOccurred()) |
| 24 | + Expect(err.Error()).Should(ContainSubstring("create plugin decoder failed")) |
| 25 | + }) |
| 26 | + }) |
| 27 | + When("options is not valid", func() { |
| 28 | + BeforeEach(func() { |
| 29 | + plugData = new(mockStruct) |
| 30 | + rawData = map[string]any{ |
| 31 | + "scm": map[string]any{"key": "not_exist"}, |
| 32 | + } |
| 33 | + }) |
| 34 | + It("should return error", func() { |
| 35 | + err := util.DecodePlugin(rawData, plugData) |
| 36 | + Expect(err).Should(HaveOccurred()) |
| 37 | + Expect(err.Error()).Should(ContainSubstring("decode plugin option failed")) |
| 38 | + }) |
| 39 | + }) |
| 40 | + |
| 41 | + When("all params are valid", func() { |
| 42 | + BeforeEach(func() { |
| 43 | + plugData = new(mockStruct) |
| 44 | + rawData = map[string]any{ |
| 45 | + "scm": map[string]any{ |
| 46 | + "url": "github.com/test/test_repo", |
| 47 | + }, |
| 48 | + } |
| 49 | + }) |
| 50 | + |
| 51 | + It("should set default value", func() { |
| 52 | + err := util.DecodePlugin(rawData, plugData) |
| 53 | + Expect(err).ShouldNot(HaveOccurred()) |
| 54 | + Expect(plugData).Should(Equal(&mockStruct{ |
| 55 | + Scm: &git.RepoInfo{ |
| 56 | + Owner: "test", |
| 57 | + Repo: "test_repo", |
| 58 | + Branch: "main", |
| 59 | + RepoType: "github", |
| 60 | + CloneURL: "github.com/test/test_repo", |
| 61 | + NeedAuth: false, |
| 62 | + }, |
| 63 | + })) |
| 64 | + }) |
| 65 | + }) |
| 66 | +}) |
0 commit comments