Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit acc05c2

Browse files
shanduurshanduur-akamai
authored andcommitted
feat: add test generator
Signed-off-by: Mateusz Urbanek <[email protected]>
1 parent e0d58f4 commit acc05c2

12 files changed

+1118
-0
lines changed

Diff for: test/generator/config-sample.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
templates: {}
2+
# chainsaw-test.yaml: "/path/to/non-default/template.gotpl"
3+
# BucketAccess.yaml: "/path/to/non-default/template.gotpl"
4+
# BucketAccessClass.yaml: "/path/to/non-default/template.gotpl"
5+
# BucketClaim.yaml: "/path/to/non-default/template.gotpl"
6+
# BucketClass.yaml: "/path/to/non-default/template.gotpl"
7+
8+
driver: sample-driver.objectstorage.k8s.io
9+
10+
deletionPolicy:
11+
- Retain
12+
- Delete
13+
14+
authenticationType:
15+
- IAM
16+
- Key
17+
18+
protocol:
19+
- S3
20+
- Azure
21+
22+
bucketClassParams:
23+
- foo: bar
24+
baz: cux
25+
- baz: cux
26+
27+
bucketAccessClassParams:
28+
- foo: bar
29+
baz: cux
30+
- baz: cux

Diff for: test/generator/config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
templates: {}
2+
driver: sample-driver.objectstorage.k8s.io
3+
deletionPolicy:
4+
- Delete
5+
authenticationType:
6+
- Key
7+
protocol:
8+
- S3
9+
bucketClassParams: []
10+
bucketAccessClassParams: []

Diff for: test/generator/config/config.go

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
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 config
18+
19+
import (
20+
"bytes"
21+
"io"
22+
"os"
23+
24+
"sigs.k8s.io/container-object-storage-interface-api/apis/objectstorage/v1alpha1"
25+
"sigs.k8s.io/yaml"
26+
)
27+
28+
// Load reads the YAML configuration from the provided file path and unmarshals it into a Config struct.
29+
// It returns a pointer to the Config struct and any error encountered during the process.
30+
func Load(path string) (*Config, error) {
31+
f, err := os.Open(path)
32+
if err != nil {
33+
return nil, err
34+
}
35+
defer f.Close()
36+
37+
buf := new(bytes.Buffer)
38+
39+
_, err = io.Copy(buf, f)
40+
if err != nil {
41+
return nil, err
42+
}
43+
44+
cfg := &Config{}
45+
46+
err = yaml.Unmarshal(buf.Bytes(), cfg)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
return cfg, nil
52+
}
53+
54+
// Config represents the configuration for generating tests.
55+
// It includes various fields like driver details, deletion policies, authentication types, protocols,
56+
// and parameters for BucketClass and BucketAccessClass.
57+
type Config struct {
58+
// Templates contains paths to the YAML templates for various resources.
59+
Templates Templates `json:"templates"`
60+
61+
// Driver is the name of the driver used in the test configuration.
62+
Driver string `json:"driver"`
63+
64+
// DeletionPolicy is a list of deletion policies to be applied in the tests.
65+
DeletionPolicy []v1alpha1.DeletionPolicy `json:"deletionPolicy"`
66+
67+
// AuthenticationType is a list of authentication types to be used in the tests.
68+
AuthenticationType []v1alpha1.AuthenticationType `json:"authenticationType"`
69+
70+
// Protocol is a list of protocols to be used in the tests.
71+
Protocol []v1alpha1.Protocol `json:"protocol"`
72+
73+
// BucketClassParams is a list of parameters for configuring BucketClass resources.
74+
BucketClassParams []map[string]string `json:"bucketClassParams"`
75+
76+
// BucketAccessClassParams is a list of parameters for configuring BucketAccessClass resources.
77+
BucketAccessClassParams []map[string]string `json:"bucketAccessClassParams"`
78+
}
79+
80+
// Templates represents the file paths to the templates used for generating various Kubernetes resources.
81+
// These templates are referenced in the test configurations.
82+
type Templates struct {
83+
// ChainsawTest is the path to the Chainsaw test YAML template.
84+
ChainsawTest string `json:"chainsaw-test.yaml"`
85+
86+
// BucketAccess is the path to the BucketAccess YAML template.
87+
BucketAccess string `json:"BucketAccess.yaml"`
88+
89+
// BucketAccessClass is the path to the BucketAccessClass YAML template.
90+
BucketAccessClass string `json:"BucketAccessClass.yaml"`
91+
92+
// BucketClaim is the path to the BucketClaim YAML template.
93+
BucketClaim string `json:"BucketClaim.yaml"`
94+
95+
// BucketClass is the path to the BucketClass YAML template.
96+
BucketClass string `json:"BucketClass.yaml"`
97+
}

0 commit comments

Comments
 (0)