Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/generate-and-build-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ jobs:
path: |
_build/install/default/share/go/*
!_build/install/default/share/go/dune
!_build/install/default/share/go/**/*_test.go

# sdk-ci runs some Go unit tests.
# This setting ensures that SDK date time
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/go-ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ runs:
working-directory: ${{ github.workspace }}/_build/install/default/share/go/src
args: --config=${{ github.workspace }}/.golangci.yml

- name: Run Go Tests
shell: bash
working-directory: ${{ github.workspace }}/_build/install/default/share/go/src
run: go test -v

- name: Run CI for Go SDK
shell: bash
run: |
Expand Down
67 changes: 67 additions & 0 deletions ocaml/sdk-gen/component-test/jsonrpc-client/go/datetime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package componenttest

import (
"testing"
"time"

"xenapi"
)

func TestDateDeserialization(t *testing.T) {
utc := time.UTC
plus3 := time.FixedZone("", 3*60*60)
vmRef := xenapi.VMRef("OpaqueRef:datetime")

cases := []struct {
testID string
want time.Time
}{
// no dashes, no colons
{"xapi-24/datetime_01", time.Date(2022, 1, 1, 12, 30, 45, 0, utc)},
{"xapi-24/datetime_02", time.Date(2022, 1, 1, 12, 30, 45, 0, utc)},
{"xapi-24/datetime_03", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_04", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_05", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_06", time.Date(2022, 1, 1, 12, 30, 45, 123000000, utc)},
{"xapi-24/datetime_07", time.Date(2022, 1, 1, 12, 30, 45, 123000000, utc)},
{"xapi-24/datetime_08", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
{"xapi-24/datetime_09", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
{"xapi-24/datetime_10", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
// no dashes, with colons
{"xapi-24/datetime_11", time.Date(2022, 1, 1, 12, 30, 45, 0, utc)},
{"xapi-24/datetime_12", time.Date(2022, 1, 1, 12, 30, 45, 0, utc)},
{"xapi-24/datetime_13", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_14", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_15", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_16", time.Date(2022, 1, 1, 12, 30, 45, 123000000, utc)},
{"xapi-24/datetime_17", time.Date(2022, 1, 1, 12, 30, 45, 123000000, utc)},
{"xapi-24/datetime_18", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
{"xapi-24/datetime_19", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
{"xapi-24/datetime_20", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
// dashes and colons
{"xapi-24/datetime_21", time.Date(2022, 1, 1, 12, 30, 45, 0, utc)},
{"xapi-24/datetime_22", time.Date(2022, 1, 1, 12, 30, 45, 0, utc)},
{"xapi-24/datetime_23", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_24", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_25", time.Date(2022, 1, 1, 12, 30, 45, 0, plus3)},
{"xapi-24/datetime_26", time.Date(2022, 1, 1, 12, 30, 45, 123000000, utc)},
{"xapi-24/datetime_27", time.Date(2022, 1, 1, 12, 30, 45, 123000000, utc)},
{"xapi-24/datetime_28", time.Date(2022, 1, 1, 12, 30, 45, 123000000, plus3)},
}

for _, c := range cases {
t.Run(c.testID, func(t *testing.T) {
session, err := GetSession(c.testID)
if err != nil {
t.Fatalf("GetSession(%s): %v", c.testID, err)
}
got, err := xenapi.VM.GetSnapshotTime(session, vmRef)
if err != nil {
t.Fatalf("GetSnapshotTime(%s): %v", c.testID, err)
}
if !c.want.Equal(got) {
t.Fatalf("%s: expected %v, got %v", c.testID, c.want, got)
}
})
}
}
30 changes: 30 additions & 0 deletions ocaml/sdk-gen/component-test/spec/xapi-24/datetime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"xapi-24/datetime_01": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045" } } },
"xapi-24/datetime_02": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045Z" } } },
"xapi-24/datetime_03": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045+03" } } },
"xapi-24/datetime_04": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045+0300" } } },
"xapi-24/datetime_05": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045+03:00" } } },
"xapi-24/datetime_06": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045.123" } } },
"xapi-24/datetime_07": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045.123Z" } } },
"xapi-24/datetime_08": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045.123+03" } } },
"xapi-24/datetime_09": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045.123+0300" } } },
"xapi-24/datetime_10": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T123045.123+03:00" } } },
"xapi-24/datetime_11": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45" } } },
"xapi-24/datetime_12": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45Z" } } },
"xapi-24/datetime_13": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45+03" } } },
"xapi-24/datetime_14": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45+0300" } } },
"xapi-24/datetime_15": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45+03:00" } } },
"xapi-24/datetime_16": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45.123" } } },
"xapi-24/datetime_17": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45.123Z" } } },
"xapi-24/datetime_18": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45.123+03" } } },
"xapi-24/datetime_19": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45.123+0300" } } },
"xapi-24/datetime_20": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "20220101T12:30:45.123+03:00" } } },
"xapi-24/datetime_21": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45" } } },
"xapi-24/datetime_22": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45Z" } } },
"xapi-24/datetime_23": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45+03" } } },
"xapi-24/datetime_24": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45+0300" } } },
"xapi-24/datetime_25": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45+03:00" } } },
"xapi-24/datetime_26": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45.123" } } },
"xapi-24/datetime_27": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45.123Z" } } },
"xapi-24/datetime_28": { "method": ["VM.get_snapshot_time"], "params": { "VM.get_snapshot_time": ["", "OpaqueRef:datetime"] }, "expected_result": { "VM.get_snapshot_time": { "result": "2022-01-01T12:30:45.123+03" } } }
}
91 changes: 0 additions & 91 deletions ocaml/sdk-gen/go/autogen/src/convert_test.go

This file was deleted.

37 changes: 0 additions & 37 deletions ocaml/sdk-gen/go/autogen/src/export_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions ocaml/sdk-gen/go/gen_go_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module Json = struct
| SecretString | String ->
("string", StringMap.empty)
| Int ->
("int", StringMap.empty)
("int64", StringMap.empty)
| Float ->
("float64", StringMap.empty)
| Bool ->
Expand Down Expand Up @@ -721,7 +721,7 @@ module Convert = struct
| SecretString | String ->
Simple {func_suffix= "String"; value_ty= "string"}
| Int ->
Int {func_suffix= "Int"; value_ty= "int"}
Int {func_suffix= "Int"; value_ty= "int64"}
| Float ->
Float {func_suffix= "Float"; value_ty= "float64"}
| Bool ->
Expand Down
2 changes: 1 addition & 1 deletion ocaml/sdk-gen/go/templates/APIVersions.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var APIVersionMap = map[string]APIVersion{
"APIVersionUnknown": APIVersionUnknown,
}

func GetAPIVersion(major int, minor int) APIVersion {
func GetAPIVersion(major int64, minor int64) APIVersion {
versionName := fmt.Sprintf("APIVersion%d_%d", major, minor)
apiVersion, ok := APIVersionMap[versionName]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions ocaml/sdk-gen/go/templates/ConvertInt.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func deserialize{{func_name_suffix}}(context string, input interface{}) (value {
return
}
strValue := fmt.Sprintf("%v", input)
value, err = strconv.Atoi(strValue)
value, err = strconv.ParseInt(strValue, 10, 64)
if err != nil {
floatValue, err1 := strconv.ParseFloat(strValue, 64)
if err1 == nil {
return int(floatValue), nil
return int64(floatValue), nil
}
}
return
Expand Down
3 changes: 1 addition & 2 deletions ocaml/sdk-gen/go/templates/ConvertTime.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ func deserialize{{func_name_suffix}}(context string, input interface{}) (value {
}
return
}
unixTimestamp, err := strconv.ParseInt(strconv.Itoa(int(floatValue)), 10, 64)
value = time.Unix(unixTimestamp, 0).UTC()
value = time.Unix(int64(floatValue), 0).UTC()

return
}
Expand Down
6 changes: 3 additions & 3 deletions ocaml/sdk-gen/go/templates/Record.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type {{name}}Ref string
type RecordInterface interface{}

type EventBatch struct {
Token string `json:"token,omitempty"`
ValidRefCounts map[string]int `json:"validRefCounts,omitempty"`
Events []EventRecord `json:"events,omitempty"`
Token string `json:"token,omitempty"`
ValidRefCounts map[string]int64 `json:"validRefCounts,omitempty"`
Events []EventRecord `json:"events,omitempty"`
}

{{/event}}
Expand Down
2 changes: 1 addition & 1 deletion ocaml/sdk-gen/go/test_data/api_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var APIVersionMap = map[string]APIVersion{
"APIVersionUnknown": APIVersionUnknown,
}

func GetAPIVersion(major int, minor int) APIVersion {
func GetAPIVersion(major int64, minor int64) APIVersion {
versionName := fmt.Sprintf("APIVersion%d_%d", major, minor)
apiVersion, ok := APIVersionMap[versionName]
if !ok {
Expand Down
8 changes: 4 additions & 4 deletions ocaml/sdk-gen/go/test_data/int_convert.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
func serializeInt(context string, value int) (int, error) {
func serializeInt(context string, value int64) (int64, error) {
_ = context
return value, nil
}

func deserializeInt(context string, input interface{}) (value int, err error) {
func deserializeInt(context string, input interface{}) (value int64, err error) {
_ = context
if input == nil {
return
}
strValue := fmt.Sprintf("%v", input)
value, err = strconv.Atoi(strValue)
value, err = strconv.ParseInt(strValue, 10, 64)
if err != nil {
floatValue, err1 := strconv.ParseFloat(strValue, 64)
if err1 == nil {
return int(floatValue), nil
return int64(floatValue), nil
}
}
return
Expand Down
3 changes: 1 addition & 2 deletions ocaml/sdk-gen/go/test_data/time_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func deserializeTime(context string, input interface{}) (value time.Time, err er
}
return
}
unixTimestamp, err := strconv.ParseInt(strconv.Itoa(int(floatValue)), 10, 64)
value = time.Unix(unixTimestamp, 0).UTC()
value = time.Unix(int64(floatValue), 0).UTC()

return
}
Loading
Loading