generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
345 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package errors | ||
|
||
import "fmt" | ||
|
||
var ( | ||
ErrInvalidType = fmt.Errorf("invalid type") | ||
ErrInvalidValue = fmt.Errorf("invalid value") | ||
ErrNilValue = fmt.Errorf("%w: nil", ErrInvalidValue) | ||
) |
63 changes: 63 additions & 0 deletions
63
hack/shoot-comparator/pkg/runtime/raw_extension_matcher.go
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,63 @@ | ||
package runtime | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/kyma-project/infrastructure-manager/hack/shoot-comparator/pkg/utilz" | ||
"github.com/onsi/gomega" | ||
"github.com/onsi/gomega/types" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
type RawExtensionMatcher struct { | ||
toMatch interface{} | ||
} | ||
|
||
func NewRawExtensionMatcher(v any) types.GomegaMatcher { | ||
return &RawExtensionMatcher{ | ||
toMatch: v, | ||
} | ||
} | ||
|
||
func (m *RawExtensionMatcher) Match(actual interface{}) (bool, error) { | ||
if actual == nil && m.toMatch == nil { | ||
return true, nil | ||
} | ||
|
||
aRawExtension, err := utilz.Get[runtime.RawExtension](actual) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
eRawExtension, err := utilz.Get[runtime.RawExtension](m.toMatch) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
sort.Sort(sortBytes(aRawExtension.Raw)) | ||
sort.Sort(sortBytes(eRawExtension.Raw)) | ||
|
||
return gomega.BeComparableTo(aRawExtension.Raw).Match(eRawExtension.Raw) | ||
} | ||
|
||
func (m *RawExtensionMatcher) NegatedFailureMessage(_ interface{}) string { | ||
return "expected should not equal actual" | ||
} | ||
|
||
func (m *RawExtensionMatcher) FailureMessage(_ interface{}) string { | ||
return "expected should equal actual" | ||
} | ||
|
||
type sortBytes []byte | ||
|
||
func (s sortBytes) Less(i, j int) bool { | ||
return s[i] < s[j] | ||
} | ||
|
||
func (s sortBytes) Swap(i, j int) { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
|
||
func (s sortBytes) Len() int { | ||
return len(s) | ||
} |
66 changes: 66 additions & 0 deletions
66
hack/shoot-comparator/pkg/runtime/raw_extension_matcher_test.go
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,66 @@ | ||
package runtime | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func loadTestdata(t *testing.T, filePath string) []byte { | ||
data, err := os.ReadFile(filePath) | ||
require.NoError(t, err) | ||
require.Greater(t, len(data), 0, "test data is empty") | ||
return data | ||
} | ||
|
||
func TestMatcher(t *testing.T) { | ||
testCases := []struct { | ||
actual interface{} | ||
expected interface{} | ||
isOK bool | ||
hasErr bool | ||
}{ | ||
{ | ||
actual: string(loadTestdata(t, "testdata/infra_cfg_azure_11.yaml")), | ||
expected: string(loadTestdata(t, "testdata/infra_cfg_azure_12.yaml")), | ||
isOK: true, | ||
hasErr: false, | ||
}, | ||
{ | ||
actual: runtime.RawExtension{}, | ||
expected: runtime.RawExtension{}, | ||
isOK: true, | ||
hasErr: false, | ||
}, | ||
{ | ||
actual: runtime.RawExtension{}, | ||
expected: nil, | ||
isOK: false, | ||
hasErr: true, | ||
}, | ||
{ | ||
actual: string(loadTestdata(t, "testdata/infra_cfg_azure_11.yaml")), | ||
expected: string(loadTestdata(t, "testdata/infra_cfg_azure_21.yaml")), | ||
isOK: false, | ||
hasErr: false, | ||
}, | ||
{ | ||
actual: []byte("invalid type"), | ||
expected: []byte("invalid type"), | ||
isOK: false, | ||
hasErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
matcher := NewRawExtensionMatcher(tc.actual) | ||
ok, err := matcher.Match(tc.expected) | ||
// THEN | ||
assert.Equal(t, tc.hasErr, err != nil, err) | ||
assert.Equal(t, tc.isOK, ok, matcher.FailureMessage(nil)) | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
hack/shoot-comparator/pkg/runtime/testdata/infra_cfg_azure_11.yaml
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,21 @@ | ||
apiVersion: azure.provider.extensions.gardener.cloud/v1alpha1 | ||
kind: InfrastructureConfig | ||
networks: | ||
vnet: | ||
cidr: 10.250.0.0/22 | ||
zones: | ||
- cidr: 10.250.0.0/25 | ||
name: 2 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 | ||
- cidr: 10.250.0.128/25 | ||
name: 3 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 | ||
- cidr: 10.250.1.0/25 | ||
name: 1 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 |
21 changes: 21 additions & 0 deletions
21
hack/shoot-comparator/pkg/runtime/testdata/infra_cfg_azure_12.yaml
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,21 @@ | ||
apiVersion: azure.provider.extensions.gardener.cloud/v1alpha1 | ||
kind: InfrastructureConfig | ||
networks: | ||
vnet: | ||
cidr: 10.250.0.0/22 | ||
zones: | ||
- cidr: 10.250.0.128/25 | ||
name: 3 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 | ||
- cidr: 10.250.1.0/25 | ||
name: 1 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 | ||
- cidr: 10.250.0.0/25 | ||
name: 2 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 |
11 changes: 11 additions & 0 deletions
11
hack/shoot-comparator/pkg/runtime/testdata/infra_cfg_azure_21.yaml
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,11 @@ | ||
apiVersion: azure.provider.extensions.gardener.cloud/v1alpha1 | ||
kind: InfrastructureConfig | ||
networks: | ||
vnet: | ||
cidr: 10.250.0.0/22 | ||
zones: | ||
- cidr: 10.250.1.0/25 | ||
name: 1 | ||
natGateway: | ||
enabled: true | ||
idleConnectionTimeoutMinutes: 4 |
6 changes: 6 additions & 0 deletions
6
hack/shoot-comparator/pkg/runtime/testdata/infra_cfg_openstack_11.yaml
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,6 @@ | ||
apiVersion: openstack.provider.extensions.gardener.cloud/v1alpha1 | ||
floatingPoolName: FloatingIP-external-kyma-01 | ||
kind: InfrastructureConfig | ||
networks: | ||
worker: '' | ||
workers: 10.250.0.0/22 |
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
Oops, something went wrong.