11package v3
22
33import (
4- //nolint:revive // ginkgo bdd
5- smoothoperatormodel "github.com/pdok/smooth-operator/model"
4+ "fmt"
5+ "sigs.k8s.io/yaml"
6+
67 "k8s.io/apimachinery/pkg/util/validation/field"
7- //"golang.org/x/net/context"
8- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9- "k8s.io/client-go/rest"
8+ "os"
109 "testing"
1110)
1211
13- var (
14- cfg * rest.Config
15- testTheme = "TEST_THEME"
16- TestTTLInt32 int32 = 30
17- )
18-
19- func getFilledAtomv3 () * Atom {
20-
21- return & Atom {
22- TypeMeta : metav1.TypeMeta {
23- Kind : "Atom" ,
24- APIVersion : "v1" ,
25- },
26- ObjectMeta : metav1.ObjectMeta {
27- Name : "v3-asis-no-error-no-warning" ,
28- Labels : map [string ]string {
29- "dataset-owner" : "test_datasetowner" ,
30- "dataset" : "test_dataset" ,
31- "theme" : testTheme ,
32- "service-type" : "test_servicetype" ,
33- },
34- },
35- Spec : AtomSpec {
36- Lifecycle : & smoothoperatormodel.Lifecycle {
37- TTLInDays : & TestTTLInt32 ,
38- },
39- },
40- }
41- }
42-
4312func TestValidateAtomWithoutClusterChecks (t * testing.T ) {
4413 myWarnings := []string {}
4514 myAllErrors := field.ErrorList {}
4615 type args struct {
47- atom * Atom
4816 warnings * []string
4917 allErrs * field.ErrorList
5018 }
@@ -54,17 +22,28 @@ func TestValidateAtomWithoutClusterChecks(t *testing.T) {
5422 }{
5523 // TODO: Add test cases.
5624 {
57- name : "MyFirstTest " ,
25+ name : "v3-asis-no-error-no-warning " ,
5826 args : args {
59- atom : getFilledAtomv3 (),
6027 warnings : & myWarnings ,
6128 allErrs : & myAllErrors ,
6229 },
6330 },
6431 }
6532 for _ , tt := range tests {
33+ input , err := os .ReadFile ("test_data/input/" + tt .name + ".yaml" )
34+ if err != nil {
35+ t .Errorf ("os.ReadFile() error = %v " , err )
36+ }
37+ atom := & Atom {}
38+ if err := yaml .Unmarshal (input , atom ); err != nil {
39+ t .Errorf ("yaml.Unmarshal() error = %v" , err )
40+ }
41+
6642 t .Run (tt .name , func (t * testing.T ) {
67- ValidateAtomWithoutClusterChecks (tt .args .atom , tt .args .warnings , tt .args .allErrs )
43+ ValidateAtomWithoutClusterChecks (atom , tt .args .warnings , tt .args .allErrs )
44+ if tt .args .warnings != nil {
45+ fmt .Printf ("tt.args.warnings: \n %v\n " , tt .args .warnings )
46+ }
6847 })
6948 }
7049}
0 commit comments