Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test suites for exporting GitHub Actions pipelines
- Loading branch information
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package orchestrators | ||
|
||
import ( | ||
"github.com/GoogleContainerTools/kpt/internal/cmdexport/types" | ||
) | ||
|
||
var githubActionsTestCases = []testCase{ | ||
{ | ||
description: "generate GitHub Actions pipeline against the current directory", | ||
config: &types.PipelineConfig{ | ||
Dir: ".", | ||
}, | ||
expected: ` | ||
name: kpt | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
Kpt: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Run all kpt functions | ||
uses: docker://gongpu/kpt:latest | ||
with: | ||
args: fn run . | ||
`, | ||
}, | ||
{ | ||
description: "generates a GitHub Actions pipeline with --fn-path", | ||
config: &types.PipelineConfig{ | ||
Dir: ".", | ||
FnPaths: []string{"functions/"}, | ||
}, | ||
expected: ` | ||
name: kpt | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
Kpt: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Run all kpt functions | ||
uses: docker://gongpu/kpt:latest | ||
with: | ||
args: fn run . --fn-path functions/ | ||
`, | ||
}, | ||
{ | ||
description: "generates a GitHub Actions pipeline with multiple function paths", | ||
config: &types.PipelineConfig{ | ||
Dir: ".", | ||
FnPaths: []string{"functions1/", "functions2/"}, | ||
}, | ||
expected: ` | ||
name: kpt | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
Kpt: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Run all kpt functions | ||
uses: docker://gongpu/kpt:latest | ||
with: | ||
args: fn run . --fn-path functions1/ functions2/ | ||
`, | ||
}, | ||
} | ||
|
||
var githubActionsTestSuite = testSuite{ | ||
pipeline: new(GitHubActions), | ||
testCases: githubActionsTestCases, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package orchestrators | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/kpt/internal/cmdexport/types" | ||
"gotest.tools/assert" | ||
) | ||
|
||
type testCase struct { | ||
description string | ||
config *types.PipelineConfig | ||
expected string | ||
} | ||
|
||
type testSuite struct { | ||
pipeline Pipeline | ||
testCases []testCase | ||
} | ||
|
||
func TestPipeline(t *testing.T) { | ||
testSuites := []testSuite{githubActionsTestSuite} | ||
|
||
for _, testSuite := range testSuites { | ||
pipeline := testSuite.pipeline | ||
testCases := testSuite.testCases | ||
|
||
for i := range testCases { | ||
testCase := testCases[i] | ||
|
||
t.Run(testCase.description, func(t *testing.T) { | ||
pipeline := pipeline.Init(testCase.config).Generate() | ||
|
||
actual := string(pipeline) | ||
expected := strings.TrimLeft(testCase.expected, "\n") | ||
|
||
assert.Equal(t, expected, actual) | ||
}) | ||
} | ||
} | ||
} |