-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: optimize class reference and add storage constraint
- Loading branch information
Showing
37 changed files
with
1,040 additions
and
604 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
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,65 @@ | ||
/* | ||
Copyright (C) 2022-2023 ApeCloud Co., Ltd | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
) | ||
|
||
func TestToResourceRequirements(t *testing.T) { | ||
var ( | ||
cpu = resource.MustParse("1") | ||
memory = resource.MustParse("1Gi") | ||
) | ||
cls := ComponentClass{ | ||
CPU: cpu, | ||
Memory: memory, | ||
} | ||
rr := cls.ToResourceRequirements() | ||
assert.True(t, rr.Requests.Cpu().Equal(cpu)) | ||
assert.True(t, rr.Requests.Memory().Equal(memory)) | ||
assert.True(t, rr.Limits.Cpu().Equal(cpu)) | ||
assert.True(t, rr.Limits.Memory().Equal(memory)) | ||
} | ||
|
||
func TestCmp(t *testing.T) { | ||
var ( | ||
cls1 = ComponentClassInstance{ | ||
ComponentClass: ComponentClass{ | ||
CPU: resource.MustParse("1"), | ||
Memory: resource.MustParse("1Gi"), | ||
}, | ||
} | ||
cls2 = ComponentClassInstance{ | ||
ComponentClass: ComponentClass{ | ||
CPU: resource.MustParse("2"), | ||
Memory: resource.MustParse("1Gi"), | ||
}, | ||
} | ||
cls3 = ComponentClassInstance{ | ||
ComponentClass: ComponentClass{ | ||
CPU: resource.MustParse("2"), | ||
Memory: resource.MustParse("2Gi"), | ||
}, | ||
} | ||
) | ||
assert.True(t, cls1.Cmp(&cls2) < 0) | ||
assert.True(t, cls2.Cmp(&cls3) < 0) | ||
} |
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
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
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
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.