Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore missing integration tests #1611

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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