|
| 1 | +package detection_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/buildpack/libbuildpack/buildplan" |
| 7 | + "github.com/cloudfoundry/npm-cnb/detection" |
| 8 | + "github.com/cloudfoundry/npm-cnb/modules" |
| 9 | + "github.com/sclevine/spec" |
| 10 | + |
| 11 | + . "github.com/onsi/gomega" |
| 12 | +) |
| 13 | + |
| 14 | +func testPlan(t *testing.T, when spec.G, it spec.S) { |
| 15 | + when("Plan", func() { |
| 16 | + it.Before(func() { |
| 17 | + RegisterTestingT(t) |
| 18 | + }) |
| 19 | + |
| 20 | + it("returns a plan for the node modules dependency", func() { |
| 21 | + plan := detection.NewPlan("1.2.3") |
| 22 | + Expect(plan).To(Equal(buildplan.Plan{ |
| 23 | + Provides: []buildplan.Provided{ |
| 24 | + {Name: modules.Dependency}, |
| 25 | + }, |
| 26 | + Requires: []buildplan.Required{ |
| 27 | + { |
| 28 | + Name: modules.NodeDependency, |
| 29 | + Version: "1.2.3", |
| 30 | + Metadata: buildplan.Metadata{ |
| 31 | + "build": true, |
| 32 | + "launch": true, |
| 33 | + "version-source": "package.json", |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + Name: modules.Dependency, |
| 38 | + Metadata: buildplan.Metadata{ |
| 39 | + "launch": true, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + })) |
| 44 | + }) |
| 45 | + |
| 46 | + when("the version number is empty", func() { |
| 47 | + it("returns a plan with an empty version-source", func() { |
| 48 | + plan := detection.NewPlan("") |
| 49 | + Expect(plan).To(Equal(buildplan.Plan{ |
| 50 | + Provides: []buildplan.Provided{ |
| 51 | + {Name: modules.Dependency}, |
| 52 | + }, |
| 53 | + Requires: []buildplan.Required{ |
| 54 | + { |
| 55 | + Name: modules.NodeDependency, |
| 56 | + Metadata: buildplan.Metadata{ |
| 57 | + "build": true, |
| 58 | + "launch": true, |
| 59 | + "version-source": "", |
| 60 | + }, |
| 61 | + }, |
| 62 | + { |
| 63 | + Name: modules.Dependency, |
| 64 | + Metadata: buildplan.Metadata{ |
| 65 | + "launch": true, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + })) |
| 70 | + }) |
| 71 | + }) |
| 72 | + }) |
| 73 | +} |
0 commit comments