-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Eventshub tests work on Windows (#361)
* Adding tests to reproduce 337 on Windows easily Signed-off-by: Chris Suszyński <[email protected]> * Adding unit test on Windows Signed-off-by: Chris Suszyński <[email protected]> * Fixing the manifest parsing on Windows * Rollback to already used github.com/stretchr/testify
- Loading branch information
Showing
9 changed files
with
229 additions
and
11 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,67 @@ | ||
# Copyright 2022 The Knative Authors. | ||
# | ||
# 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. | ||
|
||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ 'main', 'release-*' ] | ||
pull_request: | ||
branches: [ 'main', 'release-*' ] | ||
|
||
jobs: | ||
|
||
test: | ||
name: Unit Tests on Windows | ||
runs-on: windows-latest | ||
|
||
steps: | ||
|
||
- name: Set up Go 1.17 | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17.x | ||
id: go | ||
|
||
- name: Set git autocrlf to input | ||
run: git config --global core.autocrlf input | ||
id: git-crlf | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Merge upstream | ||
if: github.event_name == 'pull_request' | ||
run: | | ||
if ! git config user.name > /dev/null; then | ||
git config user.name "John Doe" | ||
fi | ||
if ! git config user.email > /dev/null; then | ||
git config user.email "johndoe@localhost" | ||
fi | ||
git remote add upstream https://github.com/${{ github.repository }}.git | ||
git fetch upstream ${{ github.base_ref }} | ||
git pull --no-rebase --no-commit upstream ${{ github.base_ref }} | ||
shell: bash | ||
|
||
- name: Test | ||
run: go run gotest.tools/[email protected] | ||
--format testname | ||
--junitfile "tmp/junit_tests.xml" | ||
--junitfile-testsuite-name relative | ||
--junitfile-testcase-classname relative | ||
--jsonfile "tmp/logfile.jsonl" -- | ||
-race -count=1 -short ./... |
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
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
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,45 @@ | ||
/* | ||
Copyright 2022 The Knative Authors | ||
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 manifest_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
testlog "knative.dev/reconciler-test/pkg/logging" | ||
"knative.dev/reconciler-test/pkg/manifest" | ||
) | ||
|
||
func TestNewYamlManifest(t *testing.T) { | ||
ns := randomString(t, 10) | ||
ctx := testlog.WithTestLogger(context.TODO(), t) | ||
data := map[string]interface{}{ | ||
"namespace": ns, | ||
} | ||
images := map[string]string{} | ||
yamlsDir, err := manifest.ParseTemplatesFS(ctx, templates, images, data) | ||
require.NoError(t, err) | ||
m, err := manifest.NewYamlManifest(ctx, yamlsDir, false, nil) | ||
require.NoError(t, err) | ||
assert.Equal(t, m.ResourceNames(), []string{ | ||
fmt.Sprintf("/%s (/v1, Kind=Namespace)", ns), | ||
fmt.Sprintf("%s/example (/v1, Kind=Pod)", ns), | ||
}) | ||
} |
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
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,62 @@ | ||
/* | ||
Copyright 2022 The Knative Authors | ||
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 manifest_test | ||
|
||
import ( | ||
"context" | ||
"crypto/rand" | ||
"embed" | ||
"encoding/base64" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
testlog "knative.dev/reconciler-test/pkg/logging" | ||
"knative.dev/reconciler-test/pkg/manifest" | ||
) | ||
|
||
//go:embed testdata/*.yaml | ||
var templates embed.FS | ||
|
||
func TestParseTemplatesFS(t *testing.T) { | ||
ns := randomString(t, 10) | ||
ctx := testlog.WithTestLogger(context.TODO(), t) | ||
data := map[string]interface{}{ | ||
"namespace": ns, | ||
} | ||
images := map[string]string{} | ||
yamlsDir, err := manifest.ParseTemplatesFS(ctx, templates, images, data) | ||
require.NoError(t, err) | ||
fileInfo, err := os.Stat(yamlsDir) | ||
require.NoError(t, err) | ||
assert.True(t, fileInfo.IsDir()) | ||
err = os.RemoveAll(yamlsDir) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func randomString(t fatalt, length int) string { | ||
bytes := make([]byte, length) | ||
if _, err := rand.Read(bytes); err != nil { | ||
t.Fatal(err) | ||
} | ||
return base64.URLEncoding.EncodeToString(bytes) | ||
} | ||
|
||
type fatalt interface { | ||
Fatal(...interface{}) | ||
} |
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,18 @@ | ||
# Copyright 2022 The Knative Authors | ||
# | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: {{ .namespace }} |
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,23 @@ | ||
# Copyright 2022 The Knative Authors | ||
# | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: example | ||
namespace: {{ .namespace }} | ||
spec: | ||
containers: | ||
- name: example | ||
image: busybox |
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