-
Notifications
You must be signed in to change notification settings - Fork 174
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
7 changed files
with
206 additions
and
29 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,40 @@ | ||
package cloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.k6.io/k6/cloudapi" | ||
) | ||
|
||
func RegisterPLZ(client *cloudapi.Client, data PLZRegistrationData) error { | ||
// url := fmt.Sprintf("https://%s/v1/load-zones", client.GetURL()) | ||
url := fmt.Sprintf("http://%s/v1/load-zones", "mock-cloud.k6-operator-system.svc.cluster.local:8080") | ||
|
||
req, err := client.NewRequest("POST", url, data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var resp struct { | ||
Error struct { | ||
Message string `json:"message"` | ||
} `json:"error"` | ||
} | ||
if err = client.Do(req, &resp); err != nil { | ||
return fmt.Errorf("Received error `%s`. Message from server `%s`", err.Error(), resp.Error.Message) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func DeRegisterPLZ(client *cloudapi.Client, name string) error { | ||
// url := fmt.Sprintf("https://%s/v1/load-zones/%s", client.GetURL(), name) | ||
url := fmt.Sprintf("http://%s/v1/load-zones/%s", "mock-cloud.k6-operator-system.svc.cluster.local:8080", name) | ||
|
||
req, err := client.NewRequest("DELETE", url, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return client.Do(req, nil) | ||
} |
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,92 @@ | ||
package cloud | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// 1 CPU in Kubernetes = 1 AWS vCPU = 1 GCP Core = 1 Azure vCore | ||
// Docs: https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/#cpu-units | ||
|
||
func TestConversion(t *testing.T) { | ||
testCases := []struct { | ||
k8sResource string | ||
expected float64 | ||
}{ | ||
// CPU | ||
{ | ||
"512m", | ||
0.512, | ||
}, | ||
{ | ||
"1000m", | ||
1, | ||
}, | ||
{ | ||
"1", | ||
1, | ||
}, | ||
{ | ||
"100", | ||
100, | ||
}, | ||
// Memory | ||
{ | ||
"104857600", | ||
104857600, | ||
}, | ||
{ | ||
"100M", | ||
100000000, | ||
}, | ||
{ | ||
"100Mi", | ||
104857600, | ||
}, | ||
{ | ||
"150Mi", | ||
157286400, | ||
}, | ||
{ | ||
"1050Mi", | ||
1101004800, | ||
}, | ||
{ | ||
"4000M", | ||
4000000000, | ||
}, | ||
{ | ||
"4000Mi", | ||
4194304000, | ||
}, | ||
{ | ||
"4Gi", | ||
4294967296, | ||
}, | ||
{ | ||
"10000Mi", | ||
10485760000, | ||
}, | ||
{ | ||
"16G", | ||
16000000000, | ||
}, | ||
{ | ||
"32G", | ||
32000000000, | ||
}, | ||
{ | ||
"64G", | ||
64000000000, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
q := resource.MustParse(testCase.k8sResource) | ||
got := q.AsApproximateFloat64() | ||
assert.Equal(t, testCase.expected, got, "testCase", testCase) | ||
} | ||
} |
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