mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-09 10:47:35 +00:00
* 🌱 add a verify rule for golang files import order This PR uses the [gci tool](https://github.com/daixiang0/gci) to make all go files' import section with a specific order, it will organize import with group with order: 1. standard library modules 2. 3rd party modules 3. modules in OCM org, like the `open-cluster-management.io/api` 4. current project `open-cluster-management.io/ocm` modules developers can use the `make fmt-imports` to format the import automatically and the `make verify-fmt-imports` to check for any violation. Signed-off-by: zhujian <jiazhu@redhat.com> * 🌱 format the go files import Signed-off-by: zhujian <jiazhu@redhat.com> --------- Signed-off-by: zhujian <jiazhu@redhat.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
workv1 "open-cluster-management.io/api/work/v1"
|
|
)
|
|
|
|
func newManifest(size int) workv1.Manifest {
|
|
data := ""
|
|
for i := 0; i < size; i++ {
|
|
data += "a"
|
|
}
|
|
|
|
obj := &unstructured.Unstructured{
|
|
Object: map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "Secret",
|
|
"metadata": map[string]interface{}{
|
|
"namespace": "test",
|
|
"name": "test",
|
|
},
|
|
"data": data,
|
|
},
|
|
}
|
|
objectStr, _ := obj.MarshalJSON()
|
|
manifest := workv1.Manifest{}
|
|
manifest.Raw = objectStr
|
|
return manifest
|
|
}
|
|
func Test_Validator(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
manifests []workv1.Manifest
|
|
expectedError error
|
|
}{
|
|
{
|
|
name: "not exceed the limit",
|
|
manifests: []workv1.Manifest{newManifest(100 * 1024), newManifest(100 * 1024)},
|
|
expectedError: nil,
|
|
},
|
|
{
|
|
name: "exceed the limit",
|
|
manifests: []workv1.Manifest{newManifest(300 * 1024), newManifest(200 * 1024)},
|
|
expectedError: fmt.Errorf("the size of manifests is 512192 bytes which exceeds the 512000 limit"),
|
|
},
|
|
}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
err := ManifestValidator.ValidateManifests(c.manifests)
|
|
if !reflect.DeepEqual(err, c.expectedError) {
|
|
t.Errorf("expected %#v but got: %#v", c.expectedError, err)
|
|
}
|
|
})
|
|
}
|
|
}
|