Skip to content

Commit

Permalink
Add test suites for exporting GitHub Actions pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuGongpu committed Jun 30, 2020
1 parent 305f48b commit 0c19e82
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
92 changes: 92 additions & 0 deletions internal/cmdexport/orchestrators/githubactions_test.go
@@ -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,
}
56 changes: 56 additions & 0 deletions internal/cmdexport/orchestrators/pipeline_test.go
@@ -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)
})
}
}
}

0 comments on commit 0c19e82

Please sign in to comment.