Skip to content

Commit 8317d77

Browse files
committed
Test support: Return AppWrappers based on prefix
1 parent e14bdb8 commit 8317d77

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

test/support/file.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package support
18+
19+
import (
20+
"os"
21+
)
22+
23+
func CreateTempFile(t Test, fileContent string) (file *os.File, err error) {
24+
file, err = os.CreateTemp("", "codeflare")
25+
if err != nil {
26+
return
27+
}
28+
29+
t.T().Cleanup(func() {
30+
os.Remove(file.Name())
31+
})
32+
33+
_, err = file.WriteString(fileContent)
34+
35+
return
36+
}

test/support/mcad.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package support
1818

1919
import (
20+
"strings"
21+
2022
"github.com/onsi/gomega"
2123
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2224

@@ -32,6 +34,22 @@ func AppWrapper(t Test, namespace *corev1.Namespace, name string) func(g gomega.
3234
}
3335
}
3436

37+
func AppWrappersWithPrefix(t Test, namespace *corev1.Namespace, prefix string) func(g gomega.Gomega) []*mcadv1beta1.AppWrapper {
38+
return func(g gomega.Gomega) []*mcadv1beta1.AppWrapper {
39+
aws, err := t.Client().MCAD().WorkloadV1beta1().AppWrappers(namespace.Name).List(t.Ctx(), metav1.ListOptions{})
40+
g.Expect(err).NotTo(gomega.HaveOccurred())
41+
42+
var filteredWrappers []*mcadv1beta1.AppWrapper
43+
for _, v := range aws.Items {
44+
if strings.HasPrefix(v.Name, prefix) {
45+
filteredWrappers = append(filteredWrappers, &v)
46+
}
47+
}
48+
49+
return filteredWrappers
50+
}
51+
}
52+
3553
func AppWrapperState(aw *mcadv1beta1.AppWrapper) mcadv1beta1.AppWrapperState {
3654
return aw.Status.State
3755
}

0 commit comments

Comments
 (0)