Skip to content

Commit 0b7bb91

Browse files
authored
Merge pull request #32 from serverscom/sync-additional-methods
add sbm ptr methods and power feeds; add ds feature,service,oob creds…
2 parents 583a2ae + fde8c6e commit 0b7bb91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1585
-71
lines changed

cmd/entities/hosts/features.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package hosts
2+
3+
import (
4+
"log"
5+
6+
serverscom "github.com/serverscom/serverscom-go-client/pkg"
7+
"github.com/serverscom/srvctl/cmd/base"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func newListDSFeaturesCmd(cmdContext *base.CmdContext) *cobra.Command {
12+
factory := func(verbose bool, args ...string) serverscom.Collection[serverscom.DedicatedServerFeature] {
13+
scClient := cmdContext.GetClient().SetVerbose(verbose).GetScClient()
14+
if len(args) == 0 {
15+
log.Fatal("Missing dedicated server ID")
16+
}
17+
id := args[0]
18+
return scClient.Hosts.DedicatedServerFeatures(id)
19+
}
20+
21+
opts := &base.BaseListOptions[serverscom.DedicatedServerFeature]{}
22+
23+
return base.NewListCmd("list-features <id>", "Dedicated server features", factory, cmdContext, opts)
24+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package hosts
2+
3+
import (
4+
"errors"
5+
"path/filepath"
6+
"testing"
7+
8+
. "github.com/onsi/gomega"
9+
serverscom "github.com/serverscom/serverscom-go-client/pkg"
10+
"github.com/serverscom/srvctl/cmd/testutils"
11+
"github.com/serverscom/srvctl/internal/mocks"
12+
"go.uber.org/mock/gomock"
13+
)
14+
15+
var (
16+
featuresFixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "hosts", "features")
17+
)
18+
19+
func TestListDSFeaturesCmd(t *testing.T) {
20+
testFeature1 := serverscom.DedicatedServerFeature{
21+
Name: "disaggregated_public_ports",
22+
Status: "deactivated",
23+
}
24+
testFeature2 := serverscom.DedicatedServerFeature{
25+
Name: "no_public_network",
26+
Status: "unavailable",
27+
}
28+
29+
testCases := []struct {
30+
name string
31+
output string
32+
args []string
33+
expectedOutput []byte
34+
expectError bool
35+
configureMock func(*mocks.MockCollection[serverscom.DedicatedServerFeature])
36+
}{
37+
{
38+
name: "list all ds features",
39+
output: "json",
40+
args: []string{"-A", testServerID},
41+
expectedOutput: testutils.ReadFixture(filepath.Join(featuresFixtureBasePath, "list_all.json")),
42+
configureMock: func(mock *mocks.MockCollection[serverscom.DedicatedServerFeature]) {
43+
mock.EXPECT().
44+
Collect(gomock.Any()).
45+
Return([]serverscom.DedicatedServerFeature{
46+
testFeature1,
47+
testFeature2,
48+
}, nil)
49+
},
50+
},
51+
{
52+
name: "list ds features",
53+
output: "json",
54+
args: []string{testServerID},
55+
expectedOutput: testutils.ReadFixture(filepath.Join(featuresFixtureBasePath, "list.json")),
56+
configureMock: func(mock *mocks.MockCollection[serverscom.DedicatedServerFeature]) {
57+
mock.EXPECT().
58+
List(gomock.Any()).
59+
Return([]serverscom.DedicatedServerFeature{
60+
testFeature1,
61+
}, nil)
62+
},
63+
},
64+
{
65+
name: "list ds features with template",
66+
args: []string{testServerID, "--template", "{{range .}}Name: {{.Name}} Status: {{.Status}}\n{{end}}"},
67+
expectedOutput: testutils.ReadFixture(filepath.Join(featuresFixtureBasePath, "list_template.txt")),
68+
configureMock: func(mock *mocks.MockCollection[serverscom.DedicatedServerFeature]) {
69+
mock.EXPECT().
70+
List(gomock.Any()).
71+
Return([]serverscom.DedicatedServerFeature{
72+
testFeature1,
73+
testFeature2,
74+
}, nil)
75+
},
76+
},
77+
{
78+
name: "list ds features with page-view",
79+
args: []string{testServerID, "--page-view"},
80+
expectedOutput: testutils.ReadFixture(filepath.Join(featuresFixtureBasePath, "list_pageview.txt")),
81+
configureMock: func(mock *mocks.MockCollection[serverscom.DedicatedServerFeature]) {
82+
mock.EXPECT().
83+
List(gomock.Any()).
84+
Return([]serverscom.DedicatedServerFeature{
85+
testFeature1,
86+
testFeature2,
87+
}, nil)
88+
},
89+
},
90+
{
91+
name: "list ds features with error",
92+
args: []string{testServerID},
93+
expectError: true,
94+
configureMock: func(mock *mocks.MockCollection[serverscom.DedicatedServerFeature]) {
95+
mock.EXPECT().
96+
List(gomock.Any()).
97+
Return(nil, errors.New("some error"))
98+
},
99+
},
100+
}
101+
102+
mockCtrl := gomock.NewController(t)
103+
defer mockCtrl.Finish()
104+
hostService := mocks.NewMockHostsService(mockCtrl)
105+
collection := mocks.NewMockCollection[serverscom.DedicatedServerFeature](mockCtrl)
106+
107+
hostService.EXPECT().DedicatedServerFeatures(gomock.Any()).Return(collection).AnyTimes()
108+
collection.EXPECT().SetParam(gomock.Any(), gomock.Any()).Return(collection).AnyTimes()
109+
110+
scClient := serverscom.NewClientWithEndpoint("", "")
111+
scClient.Hosts = hostService
112+
113+
for _, tc := range testCases {
114+
t.Run(tc.name, func(t *testing.T) {
115+
g := NewWithT(t)
116+
if tc.configureMock != nil {
117+
tc.configureMock(collection)
118+
}
119+
testCmdContext := testutils.NewTestCmdContext(scClient)
120+
cmd := NewCmd(testCmdContext)
121+
122+
args := append([]string{"hosts", "ds", "list-features"}, tc.args...)
123+
if tc.output != "" {
124+
args = append(args, "--output", tc.output)
125+
}
126+
builder := testutils.NewTestCommandBuilder().
127+
WithCommand(cmd).
128+
WithArgs(args)
129+
130+
c := builder.Build()
131+
err := c.Execute()
132+
if tc.expectError {
133+
g.Expect(err).To(HaveOccurred())
134+
} else {
135+
g.Expect(err).To(BeNil())
136+
g.Expect(builder.GetOutput()).To(BeEquivalentTo(string(tc.expectedOutput)))
137+
}
138+
})
139+
}
140+
}

cmd/entities/hosts/hosts.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func NewCmd(cmdContext *base.CmdContext) *cobra.Command {
5757
newAddDSNetworkCmd,
5858
newDeleteDSNetworkCmd,
5959
newListDSCmd,
60+
newListDSServicesCmd,
61+
newListDSFeaturesCmd,
62+
newGetDSOOBCredsCmd,
6063
},
6164
},
6265
{
@@ -90,6 +93,9 @@ func NewCmd(cmdContext *base.CmdContext) *cobra.Command {
9093
newUpdateSBMCmd,
9194
newSBMReleaseCmd,
9295
newListSBMCmd,
96+
newListSBMPTRCmd,
97+
newCreateSBMPTRCmd,
98+
newDeleteSBMPTRCmd,
9399
},
94100
},
95101
}

0 commit comments

Comments
 (0)