Skip to content

Commit

Permalink
fix: run tests for module generator in all platforms (#1496)
Browse files Browse the repository at this point in the history
* fix: run tests for module generator in all platforms

* fix: sanitise content for Windows
  • Loading branch information
mdelapenya authored Aug 11, 2023
1 parent 9013d9a commit f9f4fe5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ on:
type: boolean
default: false
description: "Run the test with rootless docker."
run-tests:
required: false
type: boolean
default: true
description: "Run the tests under conditions controlled by the caller workflow."
ryuk-disabled:
required: false
type: boolean
Expand Down Expand Up @@ -69,7 +74,7 @@ jobs:
# many (maybe, all?) images used can only be build on Linux, they don't have Windows in their manifest, and
# we can't put Windows Server in "Linux Mode" in Github actions
# another, host mode is only available on Linux, and we have tests around that, do we skip them?
if: ${{ inputs.platform == 'ubuntu-latest' }}
if: ${{ inputs.run-tests }}
working-directory: ./${{ inputs.project-directory }}
timeout-minutes: 30
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
platform: ${{ matrix.platform }}
project-directory: "."
rootless-docker: false
run-tests: ${{ matrix.platform == 'ubuntu-latest' }}
ryuk-disabled: false

# The job below is a copy of the job above, but with ryuk disabled.
Expand All @@ -44,6 +45,7 @@ jobs:
platform: "ubuntu-latest"
project-directory: "."
rootless-docker: false
run-tests: true
ryuk-disabled: true

# The job below is a copy of the job above, but with Docker rootless.
Expand All @@ -61,6 +63,7 @@ jobs:
platform: "ubuntu-latest"
project-directory: "."
rootless-docker: true
run-tests: true
ryuk-disabled: false

test-module-generator:
Expand All @@ -74,6 +77,7 @@ jobs:
platform: ${{ matrix.platform }}
project-directory: "modulegen"
rootless-docker: false
run-tests: true
ryuk-disabled: false

test-modules:
Expand All @@ -92,6 +96,7 @@ jobs:
platform: ${{ matrix.platform }}
project-directory: modules/${{ matrix.module }}
rootless-docker: false
run-tests: ${{ matrix.platform == 'ubuntu-latest' }}
ryuk-disabled: false

test-examples:
Expand All @@ -107,4 +112,5 @@ jobs:
platform: ${{ matrix.platform }}
project-directory: examples/${{ matrix.module }}
rootless-docker: false
run-tests: ${{ matrix.platform == 'ubuntu-latest' }}
ryuk-disabled: false
23 changes: 17 additions & 6 deletions modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func assertExampleDocContent(t *testing.T, example Example, exampleDocFile strin
lower := example.Lower()
title := example.Title()

data := strings.Split(string(content), "\n")
data := sanitiseContent(content)
assert.Equal(t, data[0], "# "+title)
assert.Equal(t, data[2], `Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>`)
assert.Equal(t, data[4], "## Introduction")
Expand All @@ -442,7 +442,7 @@ func assertExampleTestContent(t *testing.T, example Example, exampleTestFile str
content, err := os.ReadFile(exampleTestFile)
assert.Nil(t, err)

data := strings.Split(string(content), "\n")
data := sanitiseContent(content)
assert.Equal(t, data[0], "package "+example.Lower())
assert.Equal(t, data[7], "func Test"+example.Title()+"(t *testing.T) {")
assert.Equal(t, data[10], "\tcontainer, err := RunContainer(ctx)")
Expand All @@ -458,7 +458,7 @@ func assertExampleContent(t *testing.T, example Example, exampleFile string) {
exampleName := example.Title()
entrypoint := example.Entrypoint()

data := strings.Split(string(content), "\n")
data := sanitiseContent(content)
assert.Equal(t, data[0], "package "+lower)
assert.Equal(t, data[8], "// "+containerName+" represents the "+exampleName+" container type used in the module")
assert.Equal(t, data[9], "type "+containerName+" struct {")
Expand All @@ -473,7 +473,7 @@ func assertExampleGithubWorkflowContent(t *testing.T, example Example, exampleWo
content, err := os.ReadFile(exampleWorkflowFile)
assert.Nil(t, err)

data := strings.Split(string(content), "\n")
data := sanitiseContent(content)

modulesList, err := getModulesOrExamplesAsString(true)
assert.Nil(t, err)
Expand All @@ -489,7 +489,7 @@ func assertGoModContent(t *testing.T, example Example, goModFile string) {
content, err := os.ReadFile(goModFile)
assert.Nil(t, err)

data := strings.Split(string(content), "\n")
data := sanitiseContent(content)
assert.Equal(t, "module github.com/testcontainers/testcontainers-go/"+example.ParentDir()+"/"+example.Lower(), data[0])
assert.Equal(t, "\tgit.luolix.top/testcontainers/testcontainers-go "+example.TCVersion, data[5])
}
Expand All @@ -499,7 +499,7 @@ func assertMakefileContent(t *testing.T, example Example, makefile string) {
content, err := os.ReadFile(makefile)
assert.Nil(t, err)

data := strings.Split(string(content), "\n")
data := sanitiseContent(content)
assert.Equal(t, data[4], "\t$(MAKE) test-"+example.Lower())
}

Expand Down Expand Up @@ -533,3 +533,14 @@ func assertMkdocsExamplesNav(t *testing.T, example Example, originalConfig *MkDo
// first item is the index
assert.Equal(t, parentDir+"/index.md", examples[0], examples)
}

func sanitiseContent(bytes []byte) []string {
content := string(bytes)

// Windows uses \r\n for newlines, but we want to use \n
content = strings.ReplaceAll(content, "\r\n", "\n")

data := strings.Split(content, "\n")

return data
}

0 comments on commit f9f4fe5

Please sign in to comment.