Skip to content

Commit

Permalink
Merge pull request #1611 from paketo-buildpacks/ttlsh-fix
Browse files Browse the repository at this point in the history
Restore missing integration tests
  • Loading branch information
anthonydahanne authored May 17, 2024
2 parents 778be9e + 3d7c848 commit 654c474
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/pb-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ jobs:
richgo test ./... -run Unit
env:
RICHGO_FORCE_COLOR: "1"
- name: Run Integration Tests
run: |
#!/usr/bin/env bash
set -euo pipefail
go test ./integration/... -run Integration
30 changes: 21 additions & 9 deletions octo/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,28 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {

if len(integrationTestFiles) == 0 {
j.Steps = append(j.Steps, descriptor.Test.Steps...)
} else {
j.Steps = append(j.Steps, actions.Step{
Name: "Install richgo",
Run: StatikString("/install-richgo.sh"),
Env: map[string]string{"RICHGO_VERSION": RichGoVersion},
},
}

if len(integrationTestFiles) > 0 {
j.Steps = append(j.Steps,
actions.Step{
Name: "Install richgo",
Run: StatikString("/install-richgo.sh"),
Env: map[string]string{"RICHGO_VERSION": RichGoVersion},
},
actions.Step{
Name: "Run Tests",
Run: StatikString("/run-unit-tests.sh"),
Env: map[string]string{"RICHGO_FORCE_COLOR": "1"},
})

if !descriptor.Package.Enabled {
j.Steps = append(j.Steps,
actions.Step{
Name: "Run Integration Tests",
Run: StatikString("/run-integration-tests.sh"),
})
}
}

w.Jobs["unit"] = j
Expand Down Expand Up @@ -227,9 +238,10 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
Name: "Package Buildpack",
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"FORMAT": format,
"PACKAGES": "test",
"VERSION": "${{ steps.version.outputs.version }}",
"FORMAT": format,
"PACKAGES": "test",
"VERSION": "${{ steps.version.outputs.version }}",
"TTL_SH_PUBLISH": "false",
},
})
}
Expand Down
34 changes: 34 additions & 0 deletions octo/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ package:
})

context("there are integration tests", func() {
it.Before(func() {
var err error

Expect(os.WriteFile(filepath.Join(dir, ".github", "pipeline-descriptor.yaml"), []byte(`---
github:
username: ${{ secrets.JAVA_GITHUB_USERNAME }}
token: ${{ secrets.JAVA_GITHUB_TOKEN }}
`), 0644)).To(Succeed())
descriptor, err = octo.NewDescriptor(filepath.Join(dir, ".github", "pipeline-descriptor.yaml"))
Expect(err).To(Not(HaveOccurred()))

Expect(os.Mkdir(filepath.Join(dir, "integration"), 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(dir, "integration", "main.go"), []byte{}, 0644)).To(Succeed())
})

it("will contribute a unit test and an integration test pipeline", func() {
contribution, err := octo.ContributeTest(descriptor)
Expect(err).To(Not(HaveOccurred()))

Expect(contribution.Path).To(Equal(".github/workflows/pb-tests.yml"))

var workflow jobs
Expect(yaml.Unmarshal(contribution.Content, &workflow)).To(Succeed())

Expect(len(workflow.Jobs)).To(Equal(1))
Expect(workflow.Jobs["unit"]).To(Not(BeNil()))

unitSteps := workflow.Jobs["unit"].Steps
Expect(unitSteps[len(unitSteps)-2].Run).Should(ContainSubstring("richgo test ./... -run Unit"))
Expect(unitSteps[len(unitSteps)-1].Run).Should(ContainSubstring("go test ./integration/... -run Integration"))
})
})

context("there are integration tests when packaged", func() {
it.Before(func() {
Expect(os.Mkdir(filepath.Join(dir, "integration"), 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(dir, "integration", "main.go"), []byte{}, 0644)).To(Succeed())
Expand Down

0 comments on commit 654c474

Please sign in to comment.