From 53354e47bbba2c1a608218d7df2f3ca39396de1b Mon Sep 17 00:00:00 2001 From: Fagani Hajizada Date: Wed, 25 Mar 2026 21:44:29 +0100 Subject: [PATCH] feat: add QOS types and client interface for v0044 --- pkg/client/api/v0044/qos.go | 157 +++++++++++++++ pkg/client/api/v0044/qos_test.go | 266 ++++++++++++++++++++++++ pkg/client/api/v0044/v0044.go | 1 + pkg/client/client.go | 21 ++ pkg/types/V0044Qos.go | 78 ++++++++ pkg/types/V0044Qos_test.go | 333 +++++++++++++++++++++++++++++++ 6 files changed, 856 insertions(+) create mode 100644 pkg/client/api/v0044/qos.go create mode 100644 pkg/client/api/v0044/qos_test.go create mode 100644 pkg/types/V0044Qos.go create mode 100644 pkg/types/V0044Qos_test.go diff --git a/pkg/client/api/v0044/qos.go b/pkg/client/api/v0044/qos.go new file mode 100644 index 0000000..034f80e --- /dev/null +++ b/pkg/client/api/v0044/qos.go @@ -0,0 +1,157 @@ +// SPDX-FileCopyrightText: Copyright (C) SchedMD LLC. +// SPDX-License-Identifier: Apache-2.0 + +package v0044 + +import ( + "context" + "errors" + "net/http" + + utilerrors "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/utils/ptr" + + api "github.com/SlinkyProject/slurm-client/api/v0044" + "github.com/SlinkyProject/slurm-client/pkg/types" + "github.com/SlinkyProject/slurm-client/pkg/utils" +) + +type QosInterface interface { + CreateQos(ctx context.Context, req any) (string, error) + UpdateQos(ctx context.Context, name string, req any) error + DeleteQos(ctx context.Context, name string) error + GetQos(ctx context.Context, name string) (*types.V0044Qos, error) + ListQos(ctx context.Context) (*types.V0044QosList, error) +} + +var _ QosInterface = &SlurmClient{} + +// CreateQos implements ClientInterface +func (c *SlurmClient) CreateQos(ctx context.Context, req any) (string, error) { + r, ok := req.(api.V0044OpenapiSlurmdbdQosResp) + if !ok { + return "", errors.New("expected req to be V0044OpenapiSlurmdbdQosResp") + } + if len(r.Qos) == 0 { + return "", errors.New("expected req to contain at least one QOS entry") + } + + params := &api.SlurmdbV0044PostQosParams{} + body := api.SlurmdbV0044PostQosJSONRequestBody(r) + res, err := c.SlurmdbV0044PostQosWithResponse(ctx, params, body) + if err != nil { + return "", err + } + + if res.StatusCode() != 200 { + errs := []error{errors.New(http.StatusText(res.StatusCode()))} + if res.JSONDefault != nil { + errs = append(errs, getOpenapiErrors(res.JSONDefault.Errors)...) + } + return "", utilerrors.NewAggregate(errs) + } + + var name string + if len(r.Qos) > 0 { + name = ptr.Deref(r.Qos[0].Name, "") + } + return name, nil +} + +// DeleteQos implements ClientInterface +func (c *SlurmClient) DeleteQos(ctx context.Context, name string) error { + res, err := c.SlurmdbV0044DeleteSingleQosWithResponse(ctx, name) + if err != nil { + return err + } + + if res.StatusCode() != 200 { + errs := []error{errors.New(http.StatusText(res.StatusCode()))} + if res.JSONDefault != nil { + errs = append(errs, getOpenapiErrors(res.JSONDefault.Errors)...) + } + return utilerrors.NewAggregate(errs) + } + + return nil +} + +// UpdateQos implements ClientInterface +func (c *SlurmClient) UpdateQos(ctx context.Context, name string, req any) error { + r, ok := req.(api.V0044OpenapiSlurmdbdQosResp) + if !ok { + return errors.New("expected req to be V0044OpenapiSlurmdbdQosResp") + } + if len(r.Qos) == 0 { + return errors.New("expected req to contain at least one QOS entry") + } + + r.Qos[0].Name = &name + + params := &api.SlurmdbV0044PostQosParams{} + body := api.SlurmdbV0044PostQosJSONRequestBody(r) + res, err := c.SlurmdbV0044PostQosWithResponse(ctx, params, body) + if err != nil { + return err + } + + if res.StatusCode() != 200 { + errs := []error{errors.New(http.StatusText(res.StatusCode()))} + if res.JSONDefault != nil { + errs = append(errs, getOpenapiErrors(res.JSONDefault.Errors)...) + } + return utilerrors.NewAggregate(errs) + } + + return nil +} + +// GetQos implements ClientInterface +func (c *SlurmClient) GetQos(ctx context.Context, name string) (*types.V0044Qos, error) { + params := &api.SlurmdbV0044GetSingleQosParams{} + res, err := c.SlurmdbV0044GetSingleQosWithResponse(ctx, name, params) + if err != nil { + return nil, err + } + + if res.StatusCode() != 200 { + errs := []error{errors.New(http.StatusText(res.StatusCode()))} + if res.JSONDefault != nil { + errs = append(errs, getOpenapiErrors(res.JSONDefault.Errors)...) + } + return nil, utilerrors.NewAggregate(errs) + } + + if len(res.JSON200.Qos) == 0 { + return nil, errors.New(http.StatusText(http.StatusNotFound)) + } + + out := &types.V0044Qos{} + utils.RemarshalOrDie(res.JSON200.Qos[0], out) + return out, nil +} + +// ListQos implements ClientInterface +func (c *SlurmClient) ListQos(ctx context.Context) (*types.V0044QosList, error) { + params := &api.SlurmdbV0044GetQosParams{} + res, err := c.SlurmdbV0044GetQosWithResponse(ctx, params) + if err != nil { + return nil, err + } + + if res.StatusCode() != 200 { + errs := []error{errors.New(http.StatusText(res.StatusCode()))} + if res.JSONDefault != nil { + errs = append(errs, getOpenapiErrors(res.JSONDefault.Errors)...) + } + return nil, utilerrors.NewAggregate(errs) + } + + list := &types.V0044QosList{ + Items: make([]types.V0044Qos, len(res.JSON200.Qos)), + } + for i, item := range res.JSON200.Qos { + utils.RemarshalOrDie(item, &list.Items[i]) + } + return list, nil +} diff --git a/pkg/client/api/v0044/qos_test.go b/pkg/client/api/v0044/qos_test.go new file mode 100644 index 0000000..9a90cad --- /dev/null +++ b/pkg/client/api/v0044/qos_test.go @@ -0,0 +1,266 @@ +// SPDX-FileCopyrightText: Copyright (C) SchedMD LLC. +// SPDX-License-Identifier: Apache-2.0 + +package v0044 + +import ( + "context" + "errors" + "net/http" + "reflect" + "testing" + + "k8s.io/utils/ptr" + + api "github.com/SlinkyProject/slurm-client/api/v0044" + "github.com/SlinkyProject/slurm-client/pkg/client/api/v0044/fake" + "github.com/SlinkyProject/slurm-client/pkg/client/api/v0044/interceptor" + "github.com/SlinkyProject/slurm-client/pkg/types" +) + +func TestSlurmClient_GetQos(t *testing.T) { + type fields struct { + ClientWithResponsesInterface api.ClientWithResponsesInterface + } + type args struct { + ctx context.Context + name string + } + tests := []struct { + name string + fields fields + args args + want *types.V0044Qos + wantErr bool + }{ + { + name: "Not Found", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClient(), + }, + args: args{ + ctx: context.Background(), + name: "normal", + }, + want: nil, + wantErr: true, + }, + { + name: "Found", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClientBuilder(). + WithInterceptorFuncs(interceptor.Funcs{ + SlurmdbV0044GetSingleQosWithResponse: func(ctx context.Context, qos string, params *api.SlurmdbV0044GetSingleQosParams, reqEditors ...api.RequestEditorFn) (*api.SlurmdbV0044GetSingleQosResponse, error) { + res := &api.SlurmdbV0044GetSingleQosResponse{ + HTTPResponse: &fake.HttpSuccess, + JSON200: &api.V0044OpenapiSlurmdbdQosResp{ + Qos: []api.V0044Qos{ + {Name: ptr.To("normal")}, + }, + }, + } + return res, nil + }, + }). + Build(), + }, + args: args{ + ctx: context.Background(), + name: "normal", + }, + want: &types.V0044Qos{ + V0044Qos: api.V0044Qos{ + Name: ptr.To("normal"), + }, + }, + wantErr: false, + }, + { + name: "HTTP Status != 200", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClientBuilder(). + WithInterceptorFuncs(interceptor.Funcs{ + SlurmdbV0044GetSingleQosWithResponse: func(ctx context.Context, qos string, params *api.SlurmdbV0044GetSingleQosParams, reqEditors ...api.RequestEditorFn) (*api.SlurmdbV0044GetSingleQosResponse, error) { + res := &api.SlurmdbV0044GetSingleQosResponse{ + HTTPResponse: &http.Response{ + Status: http.StatusText(http.StatusInternalServerError), + StatusCode: http.StatusInternalServerError, + }, + JSONDefault: &api.V0044OpenapiSlurmdbdQosResp{ + Errors: &[]api.V0044OpenapiError{ + {Error: ptr.To("error 1")}, + {Error: ptr.To("error 2")}, + }, + }, + } + return res, nil + }, + }). + Build(), + }, + args: args{ + ctx: context.Background(), + name: "normal", + }, + want: nil, + wantErr: true, + }, + { + name: "HTTP Error", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClientBuilder(). + WithInterceptorFuncs(interceptor.Funcs{ + SlurmdbV0044GetSingleQosWithResponse: func(ctx context.Context, qos string, params *api.SlurmdbV0044GetSingleQosParams, reqEditors ...api.RequestEditorFn) (*api.SlurmdbV0044GetSingleQosResponse, error) { + return nil, errors.New(http.StatusText(http.StatusBadGateway)) + }, + }). + Build(), + }, + args: args{ + ctx: context.Background(), + name: "normal", + }, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &SlurmClient{ + ClientWithResponsesInterface: tt.fields.ClientWithResponsesInterface, + } + got, err := c.GetQos(tt.args.ctx, tt.args.name) + if (err != nil) != tt.wantErr { + t.Errorf("SlurmClient.GetQos() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("SlurmClient.GetQos() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestSlurmClient_ListQos(t *testing.T) { + type fields struct { + ClientWithResponsesInterface api.ClientWithResponsesInterface + } + type args struct { + ctx context.Context + } + tests := []struct { + name string + fields fields + args args + want *types.V0044QosList + wantErr bool + }{ + { + name: "Empty list", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClient(), + }, + args: args{ + ctx: context.Background(), + }, + want: &types.V0044QosList{ + Items: make([]types.V0044Qos, 0), + }, + wantErr: false, + }, + { + name: "Non-empty list", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClientBuilder(). + WithInterceptorFuncs(interceptor.Funcs{ + SlurmdbV0044GetQosWithResponse: func(ctx context.Context, params *api.SlurmdbV0044GetQosParams, reqEditors ...api.RequestEditorFn) (*api.SlurmdbV0044GetQosResponse, error) { + res := &api.SlurmdbV0044GetQosResponse{ + HTTPResponse: &fake.HttpSuccess, + JSON200: &api.V0044OpenapiSlurmdbdQosResp{ + Qos: []api.V0044Qos{ + {Name: ptr.To("normal")}, + {Name: ptr.To("short")}, + {Name: ptr.To("free")}, + }, + }, + } + return res, nil + }, + }). + Build(), + }, + args: args{ + ctx: context.Background(), + }, + want: &types.V0044QosList{ + Items: []types.V0044Qos{ + {V0044Qos: api.V0044Qos{Name: ptr.To("normal")}}, + {V0044Qos: api.V0044Qos{Name: ptr.To("short")}}, + {V0044Qos: api.V0044Qos{Name: ptr.To("free")}}, + }, + }, + wantErr: false, + }, + { + name: "HTTP Status != 200", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClientBuilder(). + WithInterceptorFuncs(interceptor.Funcs{ + SlurmdbV0044GetQosWithResponse: func(ctx context.Context, params *api.SlurmdbV0044GetQosParams, reqEditors ...api.RequestEditorFn) (*api.SlurmdbV0044GetQosResponse, error) { + res := &api.SlurmdbV0044GetQosResponse{ + HTTPResponse: &http.Response{ + Status: http.StatusText(http.StatusInternalServerError), + StatusCode: http.StatusInternalServerError, + }, + JSONDefault: &api.V0044OpenapiSlurmdbdQosResp{ + Errors: &[]api.V0044OpenapiError{ + {Error: ptr.To("error 1")}, + {Error: ptr.To("error 2")}, + }, + }, + } + return res, nil + }, + }). + Build(), + }, + args: args{ + ctx: context.Background(), + }, + want: nil, + wantErr: true, + }, + { + name: "HTTP error", + fields: fields{ + ClientWithResponsesInterface: fake.NewFakeClientBuilder(). + WithInterceptorFuncs(interceptor.Funcs{ + SlurmdbV0044GetQosWithResponse: func(ctx context.Context, params *api.SlurmdbV0044GetQosParams, reqEditors ...api.RequestEditorFn) (*api.SlurmdbV0044GetQosResponse, error) { + return nil, errors.New(http.StatusText(http.StatusBadGateway)) + }, + }). + Build(), + }, + args: args{ + ctx: context.Background(), + }, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &SlurmClient{ + ClientWithResponsesInterface: tt.fields.ClientWithResponsesInterface, + } + got, err := c.ListQos(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("SlurmClient.ListQos() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("SlurmClient.ListQos() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/client/api/v0044/v0044.go b/pkg/client/api/v0044/v0044.go index 194eeab..d1fe9c2 100644 --- a/pkg/client/api/v0044/v0044.go +++ b/pkg/client/api/v0044/v0044.go @@ -29,6 +29,7 @@ type ClientInterface interface { NodeInterface NodeResourceLayoutInterface PartitionInterface + QosInterface ReconfigureInterface ReservationInterface StatsInterface diff --git a/pkg/client/client.go b/pkg/client/client.go index 406b618..83ecf06 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -183,6 +183,11 @@ func (c *client) Create( jobId, err = c.v0044Client.CreateJobInfo(ctx, req) key = object.ObjectKey(fmt.Sprintf("%d", ptr.Deref(jobId, 0))) + case *types.V0044Qos: + var qosName string + qosName, err = c.v0044Client.CreateQos(ctx, req) + key = object.ObjectKey(qosName) + case *types.V0044ReservationInfo: var reservationName string reservationName, err = c.v0044Client.CreateReservationInfo(ctx, req) @@ -246,6 +251,8 @@ func (c *client) Delete( err = c.v0044Client.DeleteJobInfo(ctx, key) case *types.V0044Node: err = c.v0044Client.DeleteNode(ctx, key) + case *types.V0044Qos: + err = c.v0044Client.DeleteQos(ctx, key) case *types.V0044ReservationInfo: err = c.v0044Client.DeleteReservationInfo(ctx, key) @@ -313,6 +320,8 @@ func (c *client) Update( err = c.v0044Client.UpdateJobInfo(ctx, key, req) case *types.V0044Node: err = c.v0044Client.UpdateNode(ctx, key, req) + case *types.V0044Qos: + err = c.v0044Client.UpdateQos(ctx, key, req) case *types.V0044ReservationInfo: err = c.v0044Client.UpdateReservationInfo(ctx, key, req) @@ -505,6 +514,12 @@ func (c *client) Get( return err } *o = *out + case *types.V0044Qos: + out, err := c.v0044Client.GetQos(ctx, string(key)) + if err != nil { + return err + } + *o = *out case *types.V0044ReservationInfo: out, err := c.v0044Client.GetReservationInfo(ctx, string(key)) if err != nil { @@ -697,6 +712,12 @@ func (c *client) List( return err } *objList = *out + case *types.V0044QosList: + out, err := c.v0044Client.ListQos(ctx) + if err != nil { + return err + } + *objList = *out case *types.V0044ReservationInfoList: out, err := c.v0044Client.ListReservationInfo(ctx) if err != nil { diff --git a/pkg/types/V0044Qos.go b/pkg/types/V0044Qos.go new file mode 100644 index 0000000..50b2df5 --- /dev/null +++ b/pkg/types/V0044Qos.go @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: Copyright (C) SchedMD LLC. +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "k8s.io/utils/ptr" + + api "github.com/SlinkyProject/slurm-client/api/v0044" + "github.com/SlinkyProject/slurm-client/pkg/object" + "github.com/SlinkyProject/slurm-client/pkg/utils" +) + +const ( + ObjectTypeV0044Qos = "V0044Qos" +) + +type V0044Qos struct { + api.V0044Qos +} + +// GetKey implements Object. +func (o *V0044Qos) GetKey() object.ObjectKey { + return object.ObjectKey(ptr.Deref(o.Name, "")) +} + +// GetType implements Object. +func (o *V0044Qos) GetType() object.ObjectType { + return ObjectTypeV0044Qos +} + +// DeepCopyObject implements Object. +func (o *V0044Qos) DeepCopyObject() object.Object { + return o.DeepCopy() +} + +func (o *V0044Qos) DeepCopy() *V0044Qos { + out := new(V0044Qos) + utils.RemarshalOrDie(o, out) + return out +} + +type V0044QosList struct { + Items []V0044Qos +} + +// GetType implements ObjectList. +func (o *V0044QosList) GetType() object.ObjectType { + return ObjectTypeV0044Qos +} + +// GetItems implements ObjectList. +func (o *V0044QosList) GetItems() []object.Object { + list := make([]object.Object, len(o.Items)) + for i, item := range o.Items { + list[i] = item.DeepCopyObject() + } + return list +} + +// AppendItem implements ObjectList. +func (o *V0044QosList) AppendItem(object object.Object) { + out, ok := object.(*V0044Qos) + if ok { + utils.RemarshalOrDie(object, out) + o.Items = append(o.Items, *out) + } +} + +// DeepCopyObjectList implements ObjectList. +func (o *V0044QosList) DeepCopyObjectList() object.ObjectList { + out := new(V0044QosList) + out.Items = make([]V0044Qos, len(o.Items)) + for i, item := range o.Items { + out.Items[i] = *item.DeepCopy() + } + return out +} diff --git a/pkg/types/V0044Qos_test.go b/pkg/types/V0044Qos_test.go new file mode 100644 index 0000000..c487878 --- /dev/null +++ b/pkg/types/V0044Qos_test.go @@ -0,0 +1,333 @@ +// SPDX-FileCopyrightText: Copyright (C) SchedMD LLC. +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "testing" + + apiequality "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/utils/ptr" + + api "github.com/SlinkyProject/slurm-client/api/v0044" + "github.com/SlinkyProject/slurm-client/pkg/object" +) + +func TestV0044Qos_GetKey(t *testing.T) { + type fields struct { + V0044Qos api.V0044Qos + } + tests := []struct { + name string + fields fields + want object.ObjectKey + }{ + { + name: "empty", + fields: fields{ + V0044Qos: api.V0044Qos{}, + }, + want: "", + }, + { + name: "key", + fields: fields{ + V0044Qos: api.V0044Qos{Name: ptr.To("test_0")}, + }, + want: "test_0", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044Qos{ + V0044Qos: tt.fields.V0044Qos, + } + if got := o.GetKey(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044Qos.GetKey() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestV0044Qos_GetType(t *testing.T) { + type fields struct { + V0044Qos api.V0044Qos + } + tests := []struct { + name string + fields fields + want object.ObjectType + }{ + { + name: "type", + fields: fields{ + V0044Qos: api.V0044Qos{}, + }, + want: ObjectTypeV0044Qos, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044Qos{ + V0044Qos: tt.fields.V0044Qos, + } + if got := o.GetType(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044Qos.GetType() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestV0044Qos_DeepCopyObject(t *testing.T) { + type fields struct { + V0044Qos api.V0044Qos + } + tests := []struct { + name string + fields fields + want object.Object + }{ + { + name: "empty", + fields: fields{ + V0044Qos: api.V0044Qos{}, + }, + want: &V0044Qos{}, + }, + { + name: "id", + fields: fields{ + V0044Qos: api.V0044Qos{Name: ptr.To("test_0")}, + }, + want: &V0044Qos{api.V0044Qos{Name: ptr.To("test_0")}}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044Qos{ + V0044Qos: tt.fields.V0044Qos, + } + if got := o.DeepCopyObject(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044Qos.DeepCopyObject() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestV0044Qos_DeepCopy(t *testing.T) { + type fields struct { + V0044Qos api.V0044Qos + } + tests := []struct { + name string + fields fields + want *V0044Qos + }{ + { + name: "empty", + fields: fields{ + V0044Qos: api.V0044Qos{}, + }, + want: &V0044Qos{}, + }, + { + name: "id", + fields: fields{ + V0044Qos: api.V0044Qos{Name: ptr.To("test_0")}, + }, + want: &V0044Qos{api.V0044Qos{Name: ptr.To("test_0")}}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044Qos{ + V0044Qos: tt.fields.V0044Qos, + } + if got := o.DeepCopy(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044Qos.DeepCopy() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestV0044QosList_GetType(t *testing.T) { + type fields struct { + Items []V0044Qos + } + tests := []struct { + name string + fields fields + want object.ObjectType + }{ + { + name: "type", + fields: fields{ + Items: []V0044Qos{}, + }, + want: ObjectTypeV0044Qos, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044QosList{ + Items: tt.fields.Items, + } + if got := o.GetType(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044QosList.GetType() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestV0044QosList_GetItems(t *testing.T) { + type fields struct { + Items []V0044Qos + } + tests := []struct { + name string + fields fields + want []object.Object + }{ + { + name: "empty", + fields: fields{ + Items: []V0044Qos{}, + }, + want: []object.Object{}, + }, + { + name: "items", + fields: fields{ + Items: []V0044Qos{ + {V0044Qos: api.V0044Qos{Name: ptr.To("test_0")}}, + {V0044Qos: api.V0044Qos{Name: ptr.To("normal")}}, + }, + }, + want: []object.Object{ + &V0044Qos{api.V0044Qos{Name: ptr.To("test_0")}}, + &V0044Qos{api.V0044Qos{Name: ptr.To("normal")}}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044QosList{ + Items: tt.fields.Items, + } + if got := o.GetItems(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044QosList.GetItems() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestV0044QosList_AppendItem(t *testing.T) { + type fields struct { + Items []V0044Qos + } + type args struct { + object object.Object + } + tests := []struct { + name string + fields fields + args args + wantAppend bool + }{ + { + name: "nil", + fields: fields{ + Items: []V0044Qos{}, + }, + args: args{ + object: nil, + }, + wantAppend: false, + }, + { + name: "empty", + fields: fields{ + Items: []V0044Qos{}, + }, + args: args{ + object: &V0044Qos{}, + }, + wantAppend: true, + }, + { + name: "existing", + fields: fields{ + Items: []V0044Qos{ + {V0044Qos: api.V0044Qos{Name: ptr.To("test_0")}}, + {V0044Qos: api.V0044Qos{Name: ptr.To("normal")}}, + }, + }, + args: args{ + object: &V0044Qos{}, + }, + wantAppend: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044QosList{ + Items: tt.fields.Items, + } + want := len(o.GetItems()) + if tt.wantAppend { + want++ + } + o.AppendItem(tt.args.object) + got := len(o.GetItems()) + if want != got { + t.Errorf("V0044QosList.AppendItem() = %v, want %v", got, want) + } + }) + } +} + +func TestV0044QosList_DeepCopyObjectList(t *testing.T) { + type fields struct { + Items []V0044Qos + } + tests := []struct { + name string + fields fields + want object.ObjectList + }{ + { + name: "empty", + fields: fields{ + Items: []V0044Qos{}, + }, + want: &V0044QosList{ + Items: []V0044Qos{}, + }, + }, + { + name: "existing", + fields: fields{ + Items: []V0044Qos{ + {V0044Qos: api.V0044Qos{Name: ptr.To("test_0")}}, + {V0044Qos: api.V0044Qos{Name: ptr.To("normal")}}, + }, + }, + want: &V0044QosList{ + Items: []V0044Qos{ + {api.V0044Qos{Name: ptr.To("test_0")}}, + {api.V0044Qos{Name: ptr.To("normal")}}, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + o := &V0044QosList{ + Items: tt.fields.Items, + } + if got := o.DeepCopyObjectList(); !apiequality.Semantic.DeepEqual(got, tt.want) { + t.Errorf("V0044QosList.DeepCopyObjectList() = %v, want %v", got, tt.want) + } + }) + } +}