|
| 1 | +package integration_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "path/filepath" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/cloudfoundry/switchblade" |
| 8 | + "github.com/sclevine/spec" |
| 9 | + |
| 10 | + . "github.com/onsi/gomega" |
| 11 | +) |
| 12 | + |
| 13 | +func testPlay(platform switchblade.Platform, fixtures string) func(*testing.T, spec.G, spec.S) { |
| 14 | + return func(t *testing.T, context spec.G, it spec.S) { |
| 15 | + var ( |
| 16 | + Expect = NewWithT(t).Expect |
| 17 | + name string |
| 18 | + ) |
| 19 | + |
| 20 | + it.Before(func() { |
| 21 | + var err error |
| 22 | + name, err = switchblade.RandomName() |
| 23 | + Expect(err).NotTo(HaveOccurred()) |
| 24 | + }) |
| 25 | + |
| 26 | + it.After(func() { |
| 27 | + if name != "" { |
| 28 | + Expect(platform.Delete.Execute(name)).To(Succeed()) |
| 29 | + } |
| 30 | + }) |
| 31 | + |
| 32 | + context("with Play Framework 2.0", func() { |
| 33 | + it("successfully deploys a Play 2.0 dist application", func() { |
| 34 | + deployment, logs, err := platform.Deploy. |
| 35 | + WithEnv(map[string]string{ |
| 36 | + "BP_JAVA_VERSION": "11", |
| 37 | + }). |
| 38 | + Execute(name, filepath.Join(fixtures, "container_play_2.0_dist")) |
| 39 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 40 | + |
| 41 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 42 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + context("with Play Framework 2.1", func() { |
| 47 | + it("successfully deploys a Play 2.1 dist application", func() { |
| 48 | + deployment, logs, err := platform.Deploy. |
| 49 | + WithEnv(map[string]string{ |
| 50 | + "BP_JAVA_VERSION": "11", |
| 51 | + }). |
| 52 | + Execute(name, filepath.Join(fixtures, "container_play_2.1_dist")) |
| 53 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 54 | + |
| 55 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 56 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 57 | + }) |
| 58 | + |
| 59 | + it("successfully deploys a staged Play 2.1 application", func() { |
| 60 | + deployment, logs, err := platform.Deploy. |
| 61 | + WithEnv(map[string]string{ |
| 62 | + "BP_JAVA_VERSION": "11", |
| 63 | + }). |
| 64 | + Execute(name, filepath.Join(fixtures, "container_play_2.1_staged")) |
| 65 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 66 | + |
| 67 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 68 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 69 | + }) |
| 70 | + }) |
| 71 | + |
| 72 | + context("with Play Framework 2.2", func() { |
| 73 | + it("successfully deploys a Play 2.2 dist application", func() { |
| 74 | + deployment, logs, err := platform.Deploy. |
| 75 | + WithEnv(map[string]string{ |
| 76 | + "BP_JAVA_VERSION": "11", |
| 77 | + }). |
| 78 | + Execute(name, filepath.Join(fixtures, "container_play_2.2_dist")) |
| 79 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 80 | + |
| 81 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 82 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 83 | + }) |
| 84 | + |
| 85 | + it("successfully deploys a staged Play 2.2 application", func() { |
| 86 | + deployment, logs, err := platform.Deploy. |
| 87 | + WithEnv(map[string]string{ |
| 88 | + "BP_JAVA_VERSION": "11", |
| 89 | + }). |
| 90 | + Execute(name, filepath.Join(fixtures, "container_play_2.2_staged")) |
| 91 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 92 | + |
| 93 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 94 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 95 | + }) |
| 96 | + |
| 97 | + it("handles Play 2.2 application without bat file", func() { |
| 98 | + deployment, logs, err := platform.Deploy. |
| 99 | + WithEnv(map[string]string{ |
| 100 | + "BP_JAVA_VERSION": "11", |
| 101 | + }). |
| 102 | + Execute(name, filepath.Join(fixtures, "container_play_2.2_minus_bat_file")) |
| 103 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 104 | + |
| 105 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 106 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 107 | + }) |
| 108 | + }) |
| 109 | + |
| 110 | + context("with hybrid Play applications", func() { |
| 111 | + it("rejects ambiguous Play 2.1/2.2 hybrid application", func() { |
| 112 | + // This test validates that the buildpack correctly rejects ambiguous fixtures |
| 113 | + // that contain both Play 2.1 (staged/) and Play 2.2 (lib/) version markers. |
| 114 | + // This is expected security/validation behavior to prevent deployment of |
| 115 | + // malformed applications. See: lib/java_buildpack/util/play/factory.rb:47 |
| 116 | + _, logs, err := platform.Deploy. |
| 117 | + WithEnv(map[string]string{ |
| 118 | + "BP_JAVA_VERSION": "11", |
| 119 | + }). |
| 120 | + Execute(name, filepath.Join(fixtures, "container_play_2.1_2.2_hybrid")) |
| 121 | + Expect(err).To(HaveOccurred(), logs.String) |
| 122 | + |
| 123 | + Expect(logs.String()).To(ContainSubstring("Play Framework application version cannot be determined")) |
| 124 | + }) |
| 125 | + }) |
| 126 | + |
| 127 | + context("with JRE version selection", func() { |
| 128 | + it("deploys Play application with Java 17", func() { |
| 129 | + deployment, logs, err := platform.Deploy. |
| 130 | + WithEnv(map[string]string{ |
| 131 | + "BP_JAVA_VERSION": "17", |
| 132 | + }). |
| 133 | + Execute(name, filepath.Join(fixtures, "container_play_2.2_dist")) |
| 134 | + Expect(err).NotTo(HaveOccurred(), logs.String) |
| 135 | + |
| 136 | + Expect(logs.String()).To(ContainSubstring("Java Buildpack")) |
| 137 | + Expect(deployment.ExternalURL).NotTo(BeEmpty()) |
| 138 | + }) |
| 139 | + }) |
| 140 | + } |
| 141 | +} |
0 commit comments