-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: add tests for workqueue and config parser (#36)
* Test: add tests for workqueue and config parser Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * reviewable Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * fix tests Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * add boilerplate Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * add vendors to boilerplate exclusion Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> --------- Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
- Loading branch information
1 parent
d513147
commit defe4c0
Showing
20 changed files
with
1,495 additions
and
71 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
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
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,53 @@ | ||
/* | ||
Copyright 2023 The KubeVela 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 config | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNewFromFileOrDir(t *testing.T) { | ||
a := assert.New(t) | ||
// From file | ||
cf, err := NewFromFileOrDir("testdata/golden/conf.cue") | ||
a.NoError(err) | ||
a.Equal(1, len(cf.Triggers)) | ||
// From dir | ||
cd, err := NewFromFileOrDir("testdata/golden") | ||
a.NoError(err) | ||
a.Equal(4, len(cd.Triggers)) | ||
// Every trigger should be the same | ||
prev := cf.Triggers[0] | ||
for _, t := range cd.Triggers { | ||
reflect.DeepEqual(prev, t) | ||
} | ||
} | ||
|
||
func TestNewFromFileOrDirInvalid(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
// Report error if file is invalid | ||
_, err := NewFromFileOrDir("testdata/invalidext/conf.invalid") | ||
a.Error(err) | ||
|
||
// No error if files in dir is invalid, just skips | ||
c, err := NewFromFileOrDir("testdata/invalidext") | ||
a.NoError(err) | ||
a.Equal(0, len(c.Triggers)) | ||
} |
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,20 @@ | ||
triggers: [{ | ||
source: { | ||
type: "resource-watcher" | ||
properties: { | ||
clusters: [ | ||
"cn-shanghai", | ||
] | ||
apiVersion: "apps/v1" | ||
kind: "Deployment" | ||
events: [ | ||
"update", | ||
] | ||
} | ||
} | ||
filter: "context.data.status.readyReplicas == context.data.status.replicas" | ||
action: { | ||
type: "sae-record-event" | ||
properties: nameSelector: fromLabel: "workflowrun.oam.dev/name" | ||
} | ||
}] |
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,28 @@ | ||
{ | ||
"triggers": [ | ||
{ | ||
"source": { | ||
"type": "resource-watcher", | ||
"properties": { | ||
"clusters": [ | ||
"cn-shanghai" | ||
], | ||
"apiVersion": "apps/v1", | ||
"kind": "Deployment", | ||
"events": [ | ||
"update" | ||
] | ||
} | ||
}, | ||
"filter": "context.data.status.readyReplicas == context.data.status.replicas", | ||
"action": { | ||
"type": "sae-record-event", | ||
"properties": { | ||
"nameSelector": { | ||
"fromLabel": "workflowrun.oam.dev/name" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
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,16 @@ | ||
triggers: | ||
- source: | ||
type: resource-watcher | ||
properties: | ||
clusters: | ||
- "cn-shanghai" | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
events: | ||
- update | ||
filter: context.data.status.readyReplicas == context.data.status.replicas | ||
action: | ||
type: sae-record-event | ||
properties: | ||
nameSelector: | ||
fromLabel: "workflowrun.oam.dev/name" |
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,16 @@ | ||
triggers: | ||
- source: | ||
type: resource-watcher | ||
properties: | ||
clusters: | ||
- "cn-shanghai" | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
events: | ||
- update | ||
filter: context.data.status.readyReplicas == context.data.status.replicas | ||
action: | ||
type: sae-record-event | ||
properties: | ||
nameSelector: | ||
fromLabel: "workflowrun.oam.dev/name" |
Empty file.
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,27 @@ | ||
triggers: | ||
- sources: | ||
type: resource-watcher | ||
properties: | ||
apiVersion: core.oam.dev/v1alpha1 | ||
kind: WorkflowRun | ||
events: | ||
- create | ||
matchingLabels: | ||
trigger.oam.dev/watch: "true" | ||
action: | ||
type: create-event-listener | ||
- source: | ||
type: resource-watcher | ||
properties: | ||
clusters: | ||
- "cn-shanghai" | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
events: | ||
- update | ||
filter: context.data.status.readyReplicas == context.data.status.replicas | ||
action: | ||
type: sae-record-event | ||
properties: | ||
nameSelector: | ||
fromLabel: "workflowrun.oam.dev/name" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.