Skip to content

Commit

Permalink
Add back missing integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed May 15, 2024
1 parent a4a42de commit 3d7c848
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 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
23 changes: 17 additions & 6 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
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 3d7c848

Please sign in to comment.