From 99aa1f8dbe5ce2d39aba985b230d9be2511cfbf1 Mon Sep 17 00:00:00 2001 From: Oleg Isakov Date: Tue, 12 Aug 2025 17:25:05 +0300 Subject: [PATCH 1/3] add new output entities for uplink models&bandwidths --- internal/output/entities/init.go | 2 ++ internal/output/entities/uplinkbandwidths.go | 28 ++++++++++++++++++++ internal/output/entities/uplinkmodels.go | 28 ++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 internal/output/entities/uplinkbandwidths.go create mode 100644 internal/output/entities/uplinkmodels.go diff --git a/internal/output/entities/init.go b/internal/output/entities/init.go index 3665b36..020848e 100644 --- a/internal/output/entities/init.go +++ b/internal/output/entities/init.go @@ -22,4 +22,6 @@ func init() { RegisterLocationDefinition() RegisterKubernetesClusterDefinition() RegisterKubernetesClusterNodeDefinition() + RegisterUplinkOptionDefinition() + RegisterBandwidthOptionDefinition() } diff --git a/internal/output/entities/uplinkbandwidths.go b/internal/output/entities/uplinkbandwidths.go new file mode 100644 index 0000000..f6ce3a3 --- /dev/null +++ b/internal/output/entities/uplinkbandwidths.go @@ -0,0 +1,28 @@ +package entities + +import ( + "log" + "reflect" + + serverscom "github.com/serverscom/serverscom-go-client/pkg" +) + +var ( + BandwidthOptionType = reflect.TypeOf(serverscom.BandwidthOption{}) +) + +func RegisterBandwidthOptionDefinition() { + bandwidthOptionEntity := &Entity{ + fields: []Field{ + {ID: "ID", Name: "ID", Path: "ID", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Name", Name: "Name", Path: "Name", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Type", Name: "Type", Path: "Type", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Commit", Name: "Commit", Path: "Commit", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + }, + eType: BandwidthOptionType, + } + + if err := Registry.Register(bandwidthOptionEntity); err != nil { + log.Fatal(err) + } +} diff --git a/internal/output/entities/uplinkmodels.go b/internal/output/entities/uplinkmodels.go new file mode 100644 index 0000000..ee5a250 --- /dev/null +++ b/internal/output/entities/uplinkmodels.go @@ -0,0 +1,28 @@ +package entities + +import ( + "log" + "reflect" + + serverscom "github.com/serverscom/serverscom-go-client/pkg" +) + +var ( + UplinkOptionType = reflect.TypeOf(serverscom.UplinkOption{}) +) + +func RegisterUplinkOptionDefinition() { + uplinkOptionEntity := &Entity{ + fields: []Field{ + {ID: "ID", Name: "ID", Path: "ID", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Name", Name: "Name", Path: "Name", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Type", Name: "Type", Path: "Type", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Speed", Name: "Speed", Path: "Speed", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + {ID: "Redundancy", Name: "Redundancy", Path: "Redundancy", ListHandlerFunc: stringHandler, PageViewHandlerFunc: stringHandler, Default: true}, + }, + eType: UplinkOptionType, + } + if err := Registry.Register(uplinkOptionEntity); err != nil { + log.Fatal(err) + } +} From 7f018349482a2a33c53b3a231f3eafe2baf208a6 Mon Sep 17 00:00:00 2001 From: Oleg Isakov Date: Tue, 12 Aug 2025 17:28:38 +0300 Subject: [PATCH 2/3] make 'type' option separate from base list options to avoid conflicts; add new list optioins --- cmd/base/list_options.go | 100 +++++++++++++++++++++++----- cmd/entities/hosts/list.go | 1 + cmd/entities/invoices/list.go | 2 +- cmd/entities/load_balancers/list.go | 1 + cmd/entities/ssl/list.go | 1 + 5 files changed, 88 insertions(+), 17 deletions(-) diff --git a/cmd/base/list_options.go b/cmd/base/list_options.go index 98839c4..a7bd160 100644 --- a/cmd/base/list_options.go +++ b/cmd/base/list_options.go @@ -1,7 +1,7 @@ package base import ( - "log" + "fmt" "strings" serverscom "github.com/serverscom/serverscom-go-client/pkg" @@ -36,13 +36,8 @@ func (o *BaseListOptions[T]) AddFlags(cmd *cobra.Command) { flags.IntVar(&o.perPage, "per-page", 0, "Number of items per page") flags.IntVar(&o.page, "page", 0, "Page number") flags.StringVar(&o.sorting, "sorting", "", "Sort field") - flags.StringVar(&o.direction, "direction", "", "Sort direction (ASC or DESC)") + flags.StringVar(&o.direction, "direction", "", "Sort direction (asc, desc)") flags.BoolVarP(&o.allPages, "all", "A", false, "Get all pages of resources") - - flags.String("type", "", "") - if err := flags.MarkHidden("type"); err != nil { - log.Fatal(err) - } } // ApplyToCollection applies the options to a collection @@ -67,6 +62,19 @@ func (o *BaseListOptions[T]) AllPages() bool { return o.allPages } +// HiddenTypeOption adds hidden type flag. +// Used in commands that determine type from sub command rather than user input +type HiddenTypeOption[T any] struct{} + +func (o *HiddenTypeOption[T]) AddFlags(cmd *cobra.Command) { + cmd.Flags().String("type", "", "") + _ = cmd.Flags().MarkHidden("type") +} + +func (o *HiddenTypeOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { + // stub for compatibility with other options +} + // label selector option type LabelSelectorOption[T any] struct { labelSelector string @@ -127,16 +135,16 @@ func (o *ClusterIDOption[T]) ApplyToCollection(collection serverscom.Collection[ } } -// status option -type StatusOption[T any] struct { +// invoice status option +type InvoiceStatusOption[T any] struct { status string } -func (o *StatusOption[T]) AddFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.status, "status", "", "Filter results by status") +func (o *InvoiceStatusOption[T]) AddFlags(cmd *cobra.Command) { + cmd.Flags().StringVar(&o.status, "status", "", "Filter results by status (pending, outstanding, overdue, paid, canceled, reissued)") } -func (o *StatusOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { +func (o *InvoiceStatusOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { if o.status != "" { collection.SetParam("status", o.status) } @@ -149,7 +157,7 @@ type InvoiceTypeOption[T any] struct { // use itype instead of type to avoid conflict with baseList 'type' hidden flag which we use for subcommands func (o *InvoiceTypeOption[T]) AddFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.typeVal, "itype", "", "Filter results by type") + cmd.Flags().StringVar(&o.typeVal, "type", "", "Filter results by type (invoice, credit_note)") } func (o *InvoiceTypeOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { @@ -223,7 +231,7 @@ type FamilyOption[T any] struct { } func (o *FamilyOption[T]) AddFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.family, "family", "", "Set to 'ipv4' or 'ipv6'") + cmd.Flags().StringVar(&o.family, "family", "", "Filter results by IP family (ipv4, ipv6)") } func (o *FamilyOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { @@ -237,7 +245,7 @@ type InterfaceTypeOption[T any] struct { } func (o *InterfaceTypeOption[T]) AddFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.interfaceType, "interface-type", "", "Type of network interface: public, private, oob") + cmd.Flags().StringVar(&o.interfaceType, "interface-type", "", "Filter results by network interface type (public, private, oob)") } func (o *InterfaceTypeOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { @@ -251,7 +259,7 @@ type DistributionMethodOption[T any] struct { } func (o *DistributionMethodOption[T]) AddFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&o.distributionMethod, "distribution-method", "", "Distribution method: route or gateway") + cmd.Flags().StringVar(&o.distributionMethod, "distribution-method", "", "Filter results by distribution method (route, gateway)") } func (o *DistributionMethodOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { @@ -273,3 +281,63 @@ func (o *AdditionalOption[T]) ApplyToCollection(collection serverscom.Collection collection.SetParam("additional", "true") } } + +// redundancy option +type RedundancyOption[T any] struct { + redundancy bool +} + +func (o *RedundancyOption[T]) AddFlags(cmd *cobra.Command) { + cmd.Flags().BoolVar(&o.redundancy, "redundancy", false, "Filter uplinks by redundancy (true, false)") +} + +func (o *RedundancyOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { + if o.redundancy { + collection.SetParam("redundancy", "true") + } +} + +// uplink type option +type UplinkTypeOption[T any] struct { + uplinkType string +} + +func (o *UplinkTypeOption[T]) AddFlags(cmd *cobra.Command) { + cmd.Flags().StringVar(&o.uplinkType, "type", "", "Filter uplinks by type (public, private)") +} + +func (o *UplinkTypeOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { + if o.uplinkType != "" { + collection.SetParam("type", o.uplinkType) + } +} + +// operating system id option +type OperatingSystemIDOption[T any] struct { + osID int64 +} + +func (o *OperatingSystemIDOption[T]) AddFlags(cmd *cobra.Command) { + cmd.Flags().Int64Var(&o.osID, "operating-system-id", 0, "Filter uplinks by operating system ID") +} + +func (o *OperatingSystemIDOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { + if o.osID != 0 { + collection.SetParam("operating_system_id", fmt.Sprintf("%d", o.osID)) + } +} + +// bandwidth type option +type BandwidthTypeOption[T any] struct { + bandwidthType string +} + +func (o *BandwidthTypeOption[T]) AddFlags(cmd *cobra.Command) { + cmd.Flags().StringVar(&o.bandwidthType, "type", "", `Filter bandwidth options by type (bytes, bandwidth, unmetered)`) +} + +func (o *BandwidthTypeOption[T]) ApplyToCollection(collection serverscom.Collection[T]) { + if o.bandwidthType != "" { + collection.SetParam("type", o.bandwidthType) + } +} diff --git a/cmd/entities/hosts/list.go b/cmd/entities/hosts/list.go index 4f1b9fe..5a343fe 100644 --- a/cmd/entities/hosts/list.go +++ b/cmd/entities/hosts/list.go @@ -45,6 +45,7 @@ func newListCmd(cmdContext *base.CmdContext, hostType *HostTypeCmd) *cobra.Comma opts := base.NewListOptions( &hostListOptions{}, + &base.HiddenTypeOption[serverscom.Host]{}, &base.LabelSelectorOption[serverscom.Host]{}, &base.SearchPatternOption[serverscom.Host]{}, ) diff --git a/cmd/entities/invoices/list.go b/cmd/entities/invoices/list.go index f192ae3..b33ae29 100644 --- a/cmd/entities/invoices/list.go +++ b/cmd/entities/invoices/list.go @@ -14,7 +14,7 @@ func newListCmd(cmdContext *base.CmdContext) *cobra.Command { opts := base.NewListOptions( &base.BaseListOptions[serverscom.InvoiceList]{}, - &base.StatusOption[serverscom.InvoiceList]{}, + &base.InvoiceStatusOption[serverscom.InvoiceList]{}, &base.InvoiceTypeOption[serverscom.InvoiceList]{}, &base.ParentIDOption[serverscom.InvoiceList]{}, &base.CurrencyOption[serverscom.InvoiceList]{}, diff --git a/cmd/entities/load_balancers/list.go b/cmd/entities/load_balancers/list.go index 6c8a1fd..e09d9e8 100644 --- a/cmd/entities/load_balancers/list.go +++ b/cmd/entities/load_balancers/list.go @@ -20,6 +20,7 @@ func newListCmd(cmdContext *base.CmdContext, lbType *LBTypeCmd) *cobra.Command { opts := base.NewListOptions( &base.BaseListOptions[serverscom.LoadBalancer]{}, + &base.HiddenTypeOption[serverscom.LoadBalancer]{}, &base.LabelSelectorOption[serverscom.LoadBalancer]{}, &base.SearchPatternOption[serverscom.LoadBalancer]{}, &base.LocationIDOption[serverscom.LoadBalancer]{}, diff --git a/cmd/entities/ssl/list.go b/cmd/entities/ssl/list.go index ee5d458..4330471 100644 --- a/cmd/entities/ssl/list.go +++ b/cmd/entities/ssl/list.go @@ -20,6 +20,7 @@ func newListCmd(cmdContext *base.CmdContext, sslType *SSLTypeCmd) *cobra.Command opts := base.NewListOptions( &base.BaseListOptions[serverscom.SSLCertificate]{}, + &base.HiddenTypeOption[serverscom.SSLCertificate]{}, &base.LabelSelectorOption[serverscom.SSLCertificate]{}, &base.SearchPatternOption[serverscom.SSLCertificate]{}, ) From 857fa8f3e2e8fbfbdd9cafefadc1cbed27c4b3bf Mon Sep 17 00:00:00 2001 From: Oleg Isakov Date: Tue, 12 Aug 2025 17:29:30 +0300 Subject: [PATCH 3/3] add uplink-models, uplink-bandwidths cmds --- cmd/entities/uplinkbandwidths/get.go | 57 ++++ cmd/entities/uplinkbandwidths/list.go | 34 +++ .../uplinkbandwidths/uplinkbandwidths.go | 38 +++ .../uplinkbandwidths/uplinkbandwidths_test.go | 250 ++++++++++++++++++ cmd/entities/uplinkmodels/get.go | 54 ++++ cmd/entities/uplinkmodels/list.go | 33 +++ cmd/entities/uplinkmodels/uplinkmodels.go | 38 +++ .../uplinkmodels/uplinkmodels_test.go | 250 ++++++++++++++++++ cmd/root.go | 4 + testdata/entities/uplink-bandwidths/get.json | 6 + testdata/entities/uplink-bandwidths/get.txt | 2 + testdata/entities/uplink-bandwidths/get.yaml | 4 + testdata/entities/uplink-bandwidths/list.json | 8 + .../entities/uplink-bandwidths/list_all.json | 14 + .../uplink-bandwidths/list_pageview.txt | 9 + .../uplink-bandwidths/list_template.txt | 2 + testdata/entities/uplink-models/get.json | 7 + testdata/entities/uplink-models/get.txt | 2 + testdata/entities/uplink-models/get.yaml | 5 + testdata/entities/uplink-models/list.json | 9 + testdata/entities/uplink-models/list_all.json | 16 ++ .../entities/uplink-models/list_pageview.txt | 11 + .../entities/uplink-models/list_template.txt | 2 + 23 files changed, 855 insertions(+) create mode 100644 cmd/entities/uplinkbandwidths/get.go create mode 100644 cmd/entities/uplinkbandwidths/list.go create mode 100644 cmd/entities/uplinkbandwidths/uplinkbandwidths.go create mode 100644 cmd/entities/uplinkbandwidths/uplinkbandwidths_test.go create mode 100644 cmd/entities/uplinkmodels/get.go create mode 100644 cmd/entities/uplinkmodels/list.go create mode 100644 cmd/entities/uplinkmodels/uplinkmodels.go create mode 100644 cmd/entities/uplinkmodels/uplinkmodels_test.go create mode 100644 testdata/entities/uplink-bandwidths/get.json create mode 100644 testdata/entities/uplink-bandwidths/get.txt create mode 100644 testdata/entities/uplink-bandwidths/get.yaml create mode 100644 testdata/entities/uplink-bandwidths/list.json create mode 100644 testdata/entities/uplink-bandwidths/list_all.json create mode 100644 testdata/entities/uplink-bandwidths/list_pageview.txt create mode 100644 testdata/entities/uplink-bandwidths/list_template.txt create mode 100644 testdata/entities/uplink-models/get.json create mode 100644 testdata/entities/uplink-models/get.txt create mode 100644 testdata/entities/uplink-models/get.yaml create mode 100644 testdata/entities/uplink-models/list.json create mode 100644 testdata/entities/uplink-models/list_all.json create mode 100644 testdata/entities/uplink-models/list_pageview.txt create mode 100644 testdata/entities/uplink-models/list_template.txt diff --git a/cmd/entities/uplinkbandwidths/get.go b/cmd/entities/uplinkbandwidths/get.go new file mode 100644 index 0000000..5354bd3 --- /dev/null +++ b/cmd/entities/uplinkbandwidths/get.go @@ -0,0 +1,57 @@ +package uplinkbandwidths + +import ( + "fmt" + "strconv" + + "github.com/serverscom/srvctl/cmd/base" + "github.com/spf13/cobra" +) + +func newGetCmd(cmdContext *base.CmdContext) *cobra.Command { + var locationID int64 + var serverModelID int64 + var uplinkModelID int64 + + cmd := &cobra.Command{ + Use: "get ", + Short: "Get a bandwidth option for an uplink model", + Long: "Get a bandwidth option for an uplink model by id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + manager := cmdContext.GetManager() + + ctx, cancel := base.SetupContext(cmd, manager) + defer cancel() + + base.SetupProxy(cmd, manager) + + scClient := cmdContext.GetClient().SetVerbose(manager.GetVerbose(cmd)).GetScClient() + + bandwidthID, err := strconv.Atoi(args[0]) + if err != nil { + return fmt.Errorf("bandwidth id should be integer") + } + + model, err := scClient.Locations.GetBandwidthOption(ctx, locationID, serverModelID, uplinkModelID, int64(bandwidthID)) + if err != nil { + return err + } + + if model != nil { + formatter := cmdContext.GetOrCreateFormatter(cmd) + return formatter.Format(model) + } + return nil + }, + } + + cmd.Flags().Int64Var(&locationID, "location-id", 0, "Location id (int, required)") + cmd.Flags().Int64Var(&serverModelID, "server-model-id", 0, "Server model id (int, required)") + cmd.Flags().Int64Var(&uplinkModelID, "uplink-model-id", 0, "Uplink model id (int, required)") + _ = cmd.MarkFlagRequired("location-id") + _ = cmd.MarkFlagRequired("server-model-id") + _ = cmd.MarkFlagRequired("uplink-model-id") + + return cmd +} diff --git a/cmd/entities/uplinkbandwidths/list.go b/cmd/entities/uplinkbandwidths/list.go new file mode 100644 index 0000000..ba5c375 --- /dev/null +++ b/cmd/entities/uplinkbandwidths/list.go @@ -0,0 +1,34 @@ +package uplinkbandwidths + +import ( + serverscom "github.com/serverscom/serverscom-go-client/pkg" + "github.com/serverscom/srvctl/cmd/base" + "github.com/spf13/cobra" +) + +func newListCmd(cmdContext *base.CmdContext) *cobra.Command { + var locationID int64 + var serverModelID int64 + var uplinkModelID int64 + + factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.BandwidthOption] { + scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient() + return scClient.Locations.BandwidthOptions(locationID, serverModelID, uplinkModelID) + } + + opts := base.NewListOptions( + &base.BaseListOptions[serverscom.BandwidthOption]{}, + &base.BandwidthTypeOption[serverscom.BandwidthOption]{}, + ) + + cmd := base.NewListCmd("list", "uplink-bandwidths", factory, cmdContext, opts...) + + cmd.Flags().Int64Var(&locationID, "location-id", 0, "Location ID (required)") + cmd.Flags().Int64Var(&serverModelID, "server-model-id", 0, "Server Model ID (required)") + cmd.Flags().Int64Var(&uplinkModelID, "uplink-model-id", 0, "Uplink Model ID (required)") + _ = cmd.MarkFlagRequired("location-id") + _ = cmd.MarkFlagRequired("server-model-id") + _ = cmd.MarkFlagRequired("uplink-model-id") + + return cmd +} diff --git a/cmd/entities/uplinkbandwidths/uplinkbandwidths.go b/cmd/entities/uplinkbandwidths/uplinkbandwidths.go new file mode 100644 index 0000000..e0bbf73 --- /dev/null +++ b/cmd/entities/uplinkbandwidths/uplinkbandwidths.go @@ -0,0 +1,38 @@ +package uplinkbandwidths + +import ( + "log" + + serverscom "github.com/serverscom/serverscom-go-client/pkg" + "github.com/serverscom/srvctl/cmd/base" + "github.com/serverscom/srvctl/internal/output/entities" + "github.com/spf13/cobra" +) + +func NewCmd(cmdContext *base.CmdContext) *cobra.Command { + uplinkEntity, err := entities.Registry.GetEntityFromValue(serverscom.BandwidthOption{}) + if err != nil { + log.Fatal(err) + } + entitiesMap := make(map[string]entities.EntityInterface) + entitiesMap["uplink-bandwidths"] = uplinkEntity + cmd := &cobra.Command{ + Use: "uplink-bandwidths", + Short: "Manage uplink bandwidths", + PersistentPreRunE: base.CombinePreRunE( + base.CheckFormatterFlags(cmdContext, entitiesMap), + base.CheckEmptyContexts(cmdContext), + ), + Args: base.NoArgs, + Run: base.UsageRun, + } + + cmd.AddCommand( + newListCmd(cmdContext), + newGetCmd(cmdContext), + ) + + base.AddFormatFlags(cmd) + + return cmd +} diff --git a/cmd/entities/uplinkbandwidths/uplinkbandwidths_test.go b/cmd/entities/uplinkbandwidths/uplinkbandwidths_test.go new file mode 100644 index 0000000..4dec50a --- /dev/null +++ b/cmd/entities/uplinkbandwidths/uplinkbandwidths_test.go @@ -0,0 +1,250 @@ +package uplinkbandwidths + +import ( + "errors" + "fmt" + "path/filepath" + "testing" + + . "github.com/onsi/gomega" + serverscom "github.com/serverscom/serverscom-go-client/pkg" + "github.com/serverscom/srvctl/cmd/testutils" + "github.com/serverscom/srvctl/internal/mocks" + "go.uber.org/mock/gomock" +) + +var ( + bandwidthFixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "uplink-bandwidths") + testBandwidthID = int64(10) + testLocationID = int64(1) + testServerModelID = int64(100) + testUplinkModelID = int64(10) + testCommit = int64(1000) + testBandwidthOption = serverscom.BandwidthOption{ + ID: testBandwidthID, + Name: "20002 GB", + Type: "bytes", + Commit: &testCommit, + } +) + +func TestGetUplinkBandwidthCmd(t *testing.T) { + testCases := []struct { + name string + id int64 + output string + flags []string + expectedOutput []byte + expectError bool + }{ + { + name: "get uplink bandwidth in default format", + id: testBandwidthID, + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID), "--uplink-model-id", fmt.Sprint(testUplinkModelID)}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "get.txt")), + }, + { + name: "get uplink bandwidth in JSON format", + id: testBandwidthID, + output: "json", + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID), "--uplink-model-id", fmt.Sprint(testUplinkModelID)}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "get.json")), + }, + { + name: "get uplink bandwidth in YAML format", + id: testBandwidthID, + output: "yaml", + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID), "--uplink-model-id", fmt.Sprint(testUplinkModelID)}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "get.yaml")), + }, + { + name: "get uplink bandwidth with service error", + id: testBandwidthID, + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID), "--uplink-model-id", fmt.Sprint(testUplinkModelID)}, + expectError: true, + }, + { + name: "get uplink bandwidth missing required flags", + id: testBandwidthID, + expectError: true, + }, + } + + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + locationsServiceHandler := mocks.NewMockLocationsService(mockCtrl) + + scClient := serverscom.NewClientWithEndpoint("", "") + scClient.Locations = locationsServiceHandler + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + + var err error + if tc.expectError && len(tc.flags) > 0 { + err = errors.New("some error") + } + + if len(tc.flags) > 0 { + locationsServiceHandler.EXPECT(). + GetBandwidthOption(gomock.Any(), testLocationID, testServerModelID, testUplinkModelID, tc.id). + Return(&testBandwidthOption, err) + } + + testCmdContext := testutils.NewTestCmdContext(scClient) + uplinkCmd := NewCmd(testCmdContext) + + args := []string{"uplink-bandwidths", "get", fmt.Sprint(tc.id)} + if len(tc.flags) > 0 { + args = append(args, tc.flags...) + } + if tc.output != "" { + args = append(args, "--output", tc.output) + } + + builder := testutils.NewTestCommandBuilder(). + WithCommand(uplinkCmd). + WithArgs(args) + + cmd := builder.Build() + execErr := cmd.Execute() + + if tc.expectError { + g.Expect(execErr).To(HaveOccurred()) + } else { + g.Expect(execErr).To(BeNil()) + g.Expect(builder.GetOutput()).To(BeEquivalentTo(string(tc.expectedOutput))) + } + }) + } +} + +func TestListUplinkBandwidthsCmd(t *testing.T) { + b1 := testBandwidthOption + b2 := testBandwidthOption + b2.ID = testBandwidthID + 1 + b2.Name = "Unmetered" + b2.Type = "unmetered" + + testCases := []struct { + name string + output string + args []string + expectedOutput []byte + expectError bool + configureMock func(*mocks.MockCollection[serverscom.BandwidthOption]) + }{ + { + name: "list uplink bandwidths all (-A)", + output: "json", + args: []string{"-A", "--location-id", "1", "--server-model-id", "100", "--uplink-model-id", "10"}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "list_all.json")), + configureMock: func(mc *mocks.MockCollection[serverscom.BandwidthOption]) { + mc.EXPECT(). + Collect(gomock.Any()). + Return([]serverscom.BandwidthOption{b1, b2}, nil) + }, + }, + { + name: "list uplink bandwidths", + output: "json", + args: []string{"--location-id", "1", "--server-model-id", "100", "--uplink-model-id", "10"}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "list.json")), + configureMock: func(mc *mocks.MockCollection[serverscom.BandwidthOption]) { + mc.EXPECT(). + List(gomock.Any()). + Return([]serverscom.BandwidthOption{b1}, nil) + }, + }, + { + name: "list uplink bandwidths with template", + args: []string{"--template", "{{range .}}ID: {{.ID}} Name: {{.Name}}\n{{end}}", "--location-id", "1", "--server-model-id", "100", "--uplink-model-id", "10"}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "list_template.txt")), + configureMock: func(mc *mocks.MockCollection[serverscom.BandwidthOption]) { + mc.EXPECT(). + List(gomock.Any()). + Return([]serverscom.BandwidthOption{b1, b2}, nil) + }, + }, + { + name: "list uplink bandwidths with pageView", + args: []string{"--page-view", "--location-id", "1", "--server-model-id", "100", "--uplink-model-id", "10"}, + expectedOutput: testutils.ReadFixture(filepath.Join(bandwidthFixtureBasePath, "list_pageview.txt")), + configureMock: func(mc *mocks.MockCollection[serverscom.BandwidthOption]) { + mc.EXPECT(). + List(gomock.Any()). + Return([]serverscom.BandwidthOption{b1, b2}, nil) + }, + }, + { + name: "list uplink bandwidths with error", + args: []string{"--location-id", "1", "--server-model-id", "100", "--uplink-model-id", "10"}, + expectError: true, + configureMock: func(mc *mocks.MockCollection[serverscom.BandwidthOption]) { + mc.EXPECT(). + List(gomock.Any()). + Return(nil, errors.New("some error")) + }, + }, + { + name: "list uplink bandwidths missing required flags", + expectError: true, + }, + } + + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + locationsServiceHandler := mocks.NewMockLocationsService(mockCtrl) + collectionHandler := mocks.NewMockCollection[serverscom.BandwidthOption](mockCtrl) + + locationsServiceHandler.EXPECT(). + BandwidthOptions(gomock.Any(), gomock.Any(), gomock.Any()). + Return(collectionHandler). + AnyTimes() + + collectionHandler.EXPECT(). + SetParam(gomock.Any(), gomock.Any()). + Return(collectionHandler). + AnyTimes() + + scClient := serverscom.NewClientWithEndpoint("", "") + scClient.Locations = locationsServiceHandler + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + + if tc.configureMock != nil { + tc.configureMock(collectionHandler) + } + + testCmdContext := testutils.NewTestCmdContext(scClient) + uplinkCmd := NewCmd(testCmdContext) + + args := []string{"uplink-bandwidths", "list"} + if len(tc.args) > 0 { + args = append(args, tc.args...) + } + if tc.output != "" { + args = append(args, "--output", tc.output) + } + + builder := testutils.NewTestCommandBuilder(). + WithCommand(uplinkCmd). + WithArgs(args) + + cmd := builder.Build() + err := cmd.Execute() + + if tc.expectError { + g.Expect(err).To(HaveOccurred()) + } else { + g.Expect(err).To(BeNil()) + g.Expect(builder.GetOutput()).To(BeEquivalentTo(string(tc.expectedOutput))) + } + }) + } +} diff --git a/cmd/entities/uplinkmodels/get.go b/cmd/entities/uplinkmodels/get.go new file mode 100644 index 0000000..89ebe2c --- /dev/null +++ b/cmd/entities/uplinkmodels/get.go @@ -0,0 +1,54 @@ +package uplinkmodels + +import ( + "fmt" + "strconv" + + "github.com/serverscom/srvctl/cmd/base" + "github.com/spf13/cobra" +) + +func newGetCmd(cmdContext *base.CmdContext) *cobra.Command { + var locationID int64 + var serverModelID int64 + + cmd := &cobra.Command{ + Use: "get ", + Short: "Get an uplink for a server model", + Long: "Get an uplink for a server model by id", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + manager := cmdContext.GetManager() + + ctx, cancel := base.SetupContext(cmd, manager) + defer cancel() + + base.SetupProxy(cmd, manager) + + scClient := cmdContext.GetClient().SetVerbose(manager.GetVerbose(cmd)).GetScClient() + + uplinkModelID, err := strconv.Atoi(args[0]) + if err != nil { + return fmt.Errorf("uplink model id should be integer") + } + + model, err := scClient.Locations.GetUplinkOption(ctx, locationID, serverModelID, int64(uplinkModelID)) + if err != nil { + return err + } + + if model != nil { + formatter := cmdContext.GetOrCreateFormatter(cmd) + return formatter.Format(model) + } + return nil + }, + } + + cmd.Flags().Int64Var(&locationID, "location-id", 0, "Location id (int, required)") + cmd.Flags().Int64Var(&serverModelID, "server-model-id", 0, "Server model id (int, required)") + _ = cmd.MarkFlagRequired("location-id") + _ = cmd.MarkFlagRequired("server-model-id") + + return cmd +} diff --git a/cmd/entities/uplinkmodels/list.go b/cmd/entities/uplinkmodels/list.go new file mode 100644 index 0000000..36ab798 --- /dev/null +++ b/cmd/entities/uplinkmodels/list.go @@ -0,0 +1,33 @@ +package uplinkmodels + +import ( + serverscom "github.com/serverscom/serverscom-go-client/pkg" + "github.com/serverscom/srvctl/cmd/base" + "github.com/spf13/cobra" +) + +func newListCmd(cmdContext *base.CmdContext) *cobra.Command { + var locationID int64 + var serverModelID int64 + + factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.UplinkOption] { + scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient() + return scClient.Locations.UplinkOptions(locationID, serverModelID) + } + + opts := base.NewListOptions( + &base.BaseListOptions[serverscom.UplinkOption]{}, + &base.RedundancyOption[serverscom.UplinkOption]{}, + &base.UplinkTypeOption[serverscom.UplinkOption]{}, + &base.OperatingSystemIDOption[serverscom.UplinkOption]{}, + ) + + cmd := base.NewListCmd("list", "uplink-models", factory, cmdContext, opts...) + + cmd.Flags().Int64Var(&locationID, "location-id", 0, "Location ID (required)") + cmd.Flags().Int64Var(&serverModelID, "server-model-id", 0, "Server model ID (required)") + _ = cmd.MarkFlagRequired("location-id") + _ = cmd.MarkFlagRequired("server-model-id") + + return cmd +} diff --git a/cmd/entities/uplinkmodels/uplinkmodels.go b/cmd/entities/uplinkmodels/uplinkmodels.go new file mode 100644 index 0000000..15c4ee1 --- /dev/null +++ b/cmd/entities/uplinkmodels/uplinkmodels.go @@ -0,0 +1,38 @@ +package uplinkmodels + +import ( + "log" + + serverscom "github.com/serverscom/serverscom-go-client/pkg" + "github.com/serverscom/srvctl/cmd/base" + "github.com/serverscom/srvctl/internal/output/entities" + "github.com/spf13/cobra" +) + +func NewCmd(cmdContext *base.CmdContext) *cobra.Command { + uplinkEntity, err := entities.Registry.GetEntityFromValue(serverscom.UplinkOption{}) + if err != nil { + log.Fatal(err) + } + entitiesMap := make(map[string]entities.EntityInterface) + entitiesMap["uplink-models"] = uplinkEntity + cmd := &cobra.Command{ + Use: "uplink-models", + Short: "Manage uplink models", + PersistentPreRunE: base.CombinePreRunE( + base.CheckFormatterFlags(cmdContext, entitiesMap), + base.CheckEmptyContexts(cmdContext), + ), + Args: base.NoArgs, + Run: base.UsageRun, + } + + cmd.AddCommand( + newListCmd(cmdContext), + newGetCmd(cmdContext), + ) + + base.AddFormatFlags(cmd) + + return cmd +} diff --git a/cmd/entities/uplinkmodels/uplinkmodels_test.go b/cmd/entities/uplinkmodels/uplinkmodels_test.go new file mode 100644 index 0000000..5d8eb66 --- /dev/null +++ b/cmd/entities/uplinkmodels/uplinkmodels_test.go @@ -0,0 +1,250 @@ +package uplinkmodels + +import ( + "errors" + "fmt" + "path/filepath" + "testing" + + . "github.com/onsi/gomega" + serverscom "github.com/serverscom/serverscom-go-client/pkg" + "github.com/serverscom/srvctl/cmd/testutils" + "github.com/serverscom/srvctl/internal/mocks" + "go.uber.org/mock/gomock" +) + +var ( + uplinkFixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "uplink-models") + testUplinkID = int64(10) + testLocationID = int64(1) + testServerModelID = int64(100) + testUplinkOption = serverscom.UplinkOption{ + ID: testUplinkID, + Name: "Public 1 Gbps with redundancy", + Speed: 1000, + Type: "public", + Redundancy: true, + } +) + +func TestGetUplinkModelCmd(t *testing.T) { + testCases := []struct { + name string + id int64 + output string + flags []string + expectedOutput []byte + expectError bool + }{ + { + name: "get uplink model in default format", + id: testUplinkID, + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID)}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "get.txt")), + }, + { + name: "get uplink model in JSON format", + id: testUplinkID, + output: "json", + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID)}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "get.json")), + }, + { + name: "get uplink model in YAML format", + id: testUplinkID, + output: "yaml", + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID)}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "get.yaml")), + }, + { + name: "get uplink model with service error", + id: testUplinkID, + flags: []string{"--location-id", fmt.Sprint(testLocationID), "--server-model-id", fmt.Sprint(testServerModelID)}, + expectError: true, + }, + { + name: "get uplink missing required flags", + id: testUplinkID, + expectError: true, + }, + } + + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + locationsServiceHandler := mocks.NewMockLocationsService(mockCtrl) + + scClient := serverscom.NewClientWithEndpoint("", "") + scClient.Locations = locationsServiceHandler + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + + var err error + if tc.expectError && len(tc.flags) > 0 { + err = errors.New("some error") + } + + if len(tc.flags) > 0 { + locationsServiceHandler.EXPECT(). + GetUplinkOption(gomock.Any(), testLocationID, testServerModelID, tc.id). + Return(&testUplinkOption, err) + } + + testCmdContext := testutils.NewTestCmdContext(scClient) + uplinkCmd := NewCmd(testCmdContext) + + args := []string{"uplink-models", "get", fmt.Sprint(tc.id)} + if len(tc.flags) > 0 { + args = append(args, tc.flags...) + } + if tc.output != "" { + args = append(args, "--output", tc.output) + } + + builder := testutils.NewTestCommandBuilder(). + WithCommand(uplinkCmd). + WithArgs(args) + + cmd := builder.Build() + + execErr := cmd.Execute() + + if tc.expectError { + g.Expect(execErr).To(HaveOccurred()) + } else { + g.Expect(execErr).To(BeNil()) + g.Expect(builder.GetOutput()).To(BeEquivalentTo(string(tc.expectedOutput))) + } + }) + } +} + +func TestListUplinkModelsCmd(t *testing.T) { + u1 := testUplinkOption + u2 := testUplinkOption + u2.ID = testUplinkID + 1 + u2.Name = "Private 1 Gbps with redundancy" + u2.Type = "private" + + testCases := []struct { + name string + output string + args []string + expectedOutput []byte + expectError bool + configureMock func(*mocks.MockCollection[serverscom.UplinkOption]) + }{ + { + name: "list all uplink models", + output: "json", + args: []string{"-A", "--location-id", "1", "--server-model-id", "100"}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "list_all.json")), + configureMock: func(mock *mocks.MockCollection[serverscom.UplinkOption]) { + mock.EXPECT(). + Collect(gomock.Any()). + Return([]serverscom.UplinkOption{u1, u2}, nil) + }, + }, + { + name: "list uplink models", + output: "json", + args: []string{"--location-id", "1", "--server-model-id", "100"}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "list.json")), + configureMock: func(mock *mocks.MockCollection[serverscom.UplinkOption]) { + mock.EXPECT(). + List(gomock.Any()). + Return([]serverscom.UplinkOption{u1}, nil) + }, + }, + { + name: "list uplink models with template", + args: []string{"--template", "{{range .}}ID: {{.ID}} Type: {{.Type}}\n{{end}}", "--location-id", "1", "--server-model-id", "100"}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "list_template.txt")), + configureMock: func(mock *mocks.MockCollection[serverscom.UplinkOption]) { + mock.EXPECT(). + List(gomock.Any()). + Return([]serverscom.UplinkOption{u1, u2}, nil) + }, + }, + { + name: "list uplink models with pageView", + args: []string{"--page-view", "--location-id", "1", "--server-model-id", "100"}, + expectedOutput: testutils.ReadFixture(filepath.Join(uplinkFixtureBasePath, "list_pageview.txt")), + configureMock: func(mock *mocks.MockCollection[serverscom.UplinkOption]) { + mock.EXPECT(). + List(gomock.Any()). + Return([]serverscom.UplinkOption{u1, u2}, nil) + }, + }, + { + name: "list uplink models with error", + args: []string{"--location-id", "1", "--server-model-id", "100"}, + expectError: true, + configureMock: func(mock *mocks.MockCollection[serverscom.UplinkOption]) { + mock.EXPECT(). + List(gomock.Any()). + Return(nil, errors.New("some error")) + }, + }, + { + name: "list uplink models missing required flags", + expectError: true, + }, + } + + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + locationsServiceHandler := mocks.NewMockLocationsService(mockCtrl) + collectionHandler := mocks.NewMockCollection[serverscom.UplinkOption](mockCtrl) + + locationsServiceHandler.EXPECT(). + UplinkOptions(gomock.Any(), gomock.Any()). + Return(collectionHandler). + AnyTimes() + + collectionHandler.EXPECT(). + SetParam(gomock.Any(), gomock.Any()). + Return(collectionHandler). + AnyTimes() + + scClient := serverscom.NewClientWithEndpoint("", "") + scClient.Locations = locationsServiceHandler + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + + if tc.configureMock != nil { + tc.configureMock(collectionHandler) + } + + testCmdContext := testutils.NewTestCmdContext(scClient) + uplinkCmd := NewCmd(testCmdContext) + + args := []string{"uplink-models", "list"} + if len(tc.args) > 0 { + args = append(args, tc.args...) + } + if tc.output != "" { + args = append(args, "--output", tc.output) + } + + builder := testutils.NewTestCommandBuilder(). + WithCommand(uplinkCmd). + WithArgs(args) + + cmd := builder.Build() + err := cmd.Execute() + + if tc.expectError { + g.Expect(err).To(HaveOccurred()) + } else { + g.Expect(err).To(BeNil()) + g.Expect(builder.GetOutput()).To(BeEquivalentTo(string(tc.expectedOutput))) + } + }) + } +} diff --git a/cmd/root.go b/cmd/root.go index e36aa6c..7dbd6ad 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,6 +13,8 @@ import ( "github.com/serverscom/srvctl/cmd/entities/racks" sshkeys "github.com/serverscom/srvctl/cmd/entities/ssh-keys" "github.com/serverscom/srvctl/cmd/entities/ssl" + "github.com/serverscom/srvctl/cmd/entities/uplinkbandwidths" + "github.com/serverscom/srvctl/cmd/entities/uplinkmodels" "github.com/serverscom/srvctl/cmd/login" "github.com/serverscom/srvctl/internal/client" "github.com/spf13/cobra" @@ -52,6 +54,8 @@ func NewRootCmd(version string) *cobra.Command { cmd.AddCommand(account.NewCmd(cmdContext)) cmd.AddCommand(locations.NewCmd(cmdContext)) cmd.AddCommand(k8s.NewCmd(cmdContext)) + cmd.AddCommand(uplinkmodels.NewCmd(cmdContext)) + cmd.AddCommand(uplinkbandwidths.NewCmd(cmdContext)) return cmd } diff --git a/testdata/entities/uplink-bandwidths/get.json b/testdata/entities/uplink-bandwidths/get.json new file mode 100644 index 0000000..11af735 --- /dev/null +++ b/testdata/entities/uplink-bandwidths/get.json @@ -0,0 +1,6 @@ +{ + "id": 10, + "name": "20002 GB", + "type": "bytes", + "commit": 1000 +} \ No newline at end of file diff --git a/testdata/entities/uplink-bandwidths/get.txt b/testdata/entities/uplink-bandwidths/get.txt new file mode 100644 index 0000000..7301770 --- /dev/null +++ b/testdata/entities/uplink-bandwidths/get.txt @@ -0,0 +1,2 @@ +ID Name Type Commit +10 20002 GB bytes 1000 diff --git a/testdata/entities/uplink-bandwidths/get.yaml b/testdata/entities/uplink-bandwidths/get.yaml new file mode 100644 index 0000000..c684b01 --- /dev/null +++ b/testdata/entities/uplink-bandwidths/get.yaml @@ -0,0 +1,4 @@ +id: 10 +name: 20002 GB +type: bytes +commit: 1000 diff --git a/testdata/entities/uplink-bandwidths/list.json b/testdata/entities/uplink-bandwidths/list.json new file mode 100644 index 0000000..7e3453e --- /dev/null +++ b/testdata/entities/uplink-bandwidths/list.json @@ -0,0 +1,8 @@ +[ + { + "id": 10, + "name": "20002 GB", + "type": "bytes", + "commit": 1000 + } +] \ No newline at end of file diff --git a/testdata/entities/uplink-bandwidths/list_all.json b/testdata/entities/uplink-bandwidths/list_all.json new file mode 100644 index 0000000..a0f11ec --- /dev/null +++ b/testdata/entities/uplink-bandwidths/list_all.json @@ -0,0 +1,14 @@ +[ + { + "id": 10, + "name": "20002 GB", + "type": "bytes", + "commit": 1000 + }, + { + "id": 11, + "name": "Unmetered", + "type": "unmetered", + "commit": 1000 + } +] \ No newline at end of file diff --git a/testdata/entities/uplink-bandwidths/list_pageview.txt b/testdata/entities/uplink-bandwidths/list_pageview.txt new file mode 100644 index 0000000..14b2854 --- /dev/null +++ b/testdata/entities/uplink-bandwidths/list_pageview.txt @@ -0,0 +1,9 @@ +ID: 10 +Name: 20002 GB +Type: bytes +Commit: 1000 +--- +ID: 11 +Name: Unmetered +Type: unmetered +Commit: 1000 diff --git a/testdata/entities/uplink-bandwidths/list_template.txt b/testdata/entities/uplink-bandwidths/list_template.txt new file mode 100644 index 0000000..dc7e0be --- /dev/null +++ b/testdata/entities/uplink-bandwidths/list_template.txt @@ -0,0 +1,2 @@ +ID: 10 Name: 20002 GB +ID: 11 Name: Unmetered diff --git a/testdata/entities/uplink-models/get.json b/testdata/entities/uplink-models/get.json new file mode 100644 index 0000000..02c78e6 --- /dev/null +++ b/testdata/entities/uplink-models/get.json @@ -0,0 +1,7 @@ +{ + "id": 10, + "name": "Public 1 Gbps with redundancy", + "type": "public", + "speed": 1000, + "redundancy": true +} \ No newline at end of file diff --git a/testdata/entities/uplink-models/get.txt b/testdata/entities/uplink-models/get.txt new file mode 100644 index 0000000..fbbd90f --- /dev/null +++ b/testdata/entities/uplink-models/get.txt @@ -0,0 +1,2 @@ +ID Name Type Speed Redundancy +10 Public 1 Gbps with redundancy public 1000 true diff --git a/testdata/entities/uplink-models/get.yaml b/testdata/entities/uplink-models/get.yaml new file mode 100644 index 0000000..6fd3522 --- /dev/null +++ b/testdata/entities/uplink-models/get.yaml @@ -0,0 +1,5 @@ +id: 10 +name: Public 1 Gbps with redundancy +type: public +speed: 1000 +redundancy: true diff --git a/testdata/entities/uplink-models/list.json b/testdata/entities/uplink-models/list.json new file mode 100644 index 0000000..dedb9aa --- /dev/null +++ b/testdata/entities/uplink-models/list.json @@ -0,0 +1,9 @@ +[ + { + "id": 10, + "name": "Public 1 Gbps with redundancy", + "type": "public", + "speed": 1000, + "redundancy": true + } +] \ No newline at end of file diff --git a/testdata/entities/uplink-models/list_all.json b/testdata/entities/uplink-models/list_all.json new file mode 100644 index 0000000..3014f94 --- /dev/null +++ b/testdata/entities/uplink-models/list_all.json @@ -0,0 +1,16 @@ +[ + { + "id": 10, + "name": "Public 1 Gbps with redundancy", + "type": "public", + "speed": 1000, + "redundancy": true + }, + { + "id": 11, + "name": "Private 1 Gbps with redundancy", + "type": "private", + "speed": 1000, + "redundancy": true + } +] \ No newline at end of file diff --git a/testdata/entities/uplink-models/list_pageview.txt b/testdata/entities/uplink-models/list_pageview.txt new file mode 100644 index 0000000..a5a800c --- /dev/null +++ b/testdata/entities/uplink-models/list_pageview.txt @@ -0,0 +1,11 @@ +ID: 10 +Name: Public 1 Gbps with redundancy +Type: public +Speed: 1000 +Redundancy: true +--- +ID: 11 +Name: Private 1 Gbps with redundancy +Type: private +Speed: 1000 +Redundancy: true diff --git a/testdata/entities/uplink-models/list_template.txt b/testdata/entities/uplink-models/list_template.txt new file mode 100644 index 0000000..d9cde7b --- /dev/null +++ b/testdata/entities/uplink-models/list_template.txt @@ -0,0 +1,2 @@ +ID: 10 Type: public +ID: 11 Type: private