Skip to content

Commit 6683337

Browse files
Feat/stackitcli 398 snaplock expiry time (#1405)
* feat(sfs) print snaplockExpiryTime for list/describe/create cmds STACKITCLI-398 * feat(sfs) print snaplockExpiryTime for update cmd
1 parent 8e2e8c0 commit 6683337

8 files changed

Lines changed: 83 additions & 1 deletion

File tree

internal/cmd/beta/sfs/snapshot/create/create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ func outputResult(p *print.Printer, outputFormat, snapshotLabel, resourcePoolLab
136136
snapshotLabel,
137137
resourcePoolLabel,
138138
)
139+
140+
if resp.ResourcePoolSnapshot.SnaplockExpiryTime.IsSet() && resp.ResourcePoolSnapshot.SnaplockExpiryTime.Get() != nil {
141+
p.Outputf("Snaplock expiry time: %s\n", utils.ConvertTimePToDateTimeString(resp.ResourcePoolSnapshot.SnaplockExpiryTime.Get()))
142+
}
143+
139144
return nil
140145
})
141146
}

internal/cmd/beta/sfs/snapshot/create/create_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package create
33
import (
44
"context"
55
"testing"
6+
"time"
67

78
"github.com/google/go-cmp/cmp"
89
"github.com/google/go-cmp/cmp/cmpopts"
@@ -205,6 +206,17 @@ func TestOutputResult(t *testing.T) {
205206
},
206207
wantErr: false,
207208
},
209+
{
210+
name: "set full snapshot",
211+
args: args{
212+
resp: &sfs.CreateResourcePoolSnapshotResponse{
213+
ResourcePoolSnapshot: &sfs.ResourcePoolSnapshot{
214+
SnaplockExpiryTime: *sfs.NewNullableTime(utils.Ptr(time.Now().Add(time.Hour))),
215+
},
216+
},
217+
},
218+
wantErr: false,
219+
},
208220
}
209221
params := testparams.NewTestParams()
210222

internal/cmd/beta/sfs/snapshot/describe/describe.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func outputResult(p *print.Printer, outputFormat string, resp *sfs.GetResourcePo
109109
table := tables.NewTable()
110110

111111
snap := *resp.ResourcePoolSnapshot
112+
var snaplockExpiryTime string
113+
if snap.SnaplockExpiryTime.IsSet() && snap.SnaplockExpiryTime.Get() != nil {
114+
snaplockExpiryTime = utils.ConvertTimePToDateTimeString(snap.SnaplockExpiryTime.Get())
115+
}
112116
table.AddRow("NAME", utils.PtrString(snap.SnapshotName))
113117
table.AddSeparator()
114118
if snap.Comment.IsSet() && snap.Comment.Get() != nil {
@@ -123,6 +127,8 @@ func outputResult(p *print.Printer, outputFormat string, resp *sfs.GetResourcePo
123127
table.AddSeparator()
124128
table.AddRow("CREATED AT", utils.ConvertTimePToDateTimeString(snap.CreatedAt))
125129
table.AddSeparator()
130+
table.AddRow("SNAPLOCK EXPIRY TIME", snaplockExpiryTime)
131+
table.AddSeparator()
126132

127133
p.Outputln(table.Render())
128134
return nil

internal/cmd/beta/sfs/snapshot/describe/describe_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package describe
33
import (
44
"context"
55
"testing"
6+
"time"
67

78
"github.com/google/go-cmp/cmp"
89
"github.com/google/go-cmp/cmp/cmpopts"
@@ -12,6 +13,7 @@ import (
1213
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1517
)
1618

1719
var projectIdFlag = globalflags.ProjectIdFlag
@@ -212,14 +214,30 @@ func TestOutputResult(t *testing.T) {
212214
wantErr: false,
213215
},
214216
{
215-
name: " set empty snapshot",
217+
name: "set empty snapshot",
216218
args: args{
217219
resp: &sfs.GetResourcePoolSnapshotResponse{
218220
ResourcePoolSnapshot: &sfs.ResourcePoolSnapshot{},
219221
},
220222
},
221223
wantErr: false,
222224
},
225+
{
226+
name: "set full snapshot",
227+
args: args{
228+
resp: &sfs.GetResourcePoolSnapshotResponse{
229+
ResourcePoolSnapshot: &sfs.ResourcePoolSnapshot{
230+
SnapshotName: utils.Ptr("name"),
231+
ResourcePoolId: utils.Ptr("rp-id"),
232+
SizeGigabytes: utils.Ptr(int32(10)),
233+
LogicalSizeGigabytes: utils.Ptr(int32(8)),
234+
CreatedAt: utils.Ptr(time.Now()),
235+
SnaplockExpiryTime: *sfs.NewNullableTime(utils.Ptr(time.Now().Add(time.Hour))),
236+
},
237+
},
238+
},
239+
wantErr: false,
240+
},
223241
}
224242
params := testparams.NewTestParams()
225243

internal/cmd/beta/sfs/snapshot/list/list.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,26 @@ func outputResult(p *print.Printer, outputFormat string, resp []sfs.ResourcePool
126126
"SIZE (GB)",
127127
"LOGICAL SIZE (GB)",
128128
"CREATED AT",
129+
"SNAPLOCK EXPIRY TIME",
129130
)
130131

131132
for _, snap := range resp {
132133
var comment string
133134
if snap.Comment.IsSet() && snap.Comment.Get() != nil {
134135
comment = utils.PtrString(snap.Comment.Get())
135136
}
137+
var snaplockExpiryTime string
138+
if snap.SnaplockExpiryTime.IsSet() && snap.SnaplockExpiryTime.Get() != nil {
139+
snaplockExpiryTime = utils.ConvertTimePToDateTimeString(snap.SnaplockExpiryTime.Get())
140+
}
136141
table.AddRow(
137142
utils.PtrString(snap.SnapshotName),
138143
comment,
139144
utils.PtrString(snap.ResourcePoolId),
140145
utils.PtrString(snap.SizeGigabytes),
141146
utils.PtrString(snap.LogicalSizeGigabytes),
142147
utils.ConvertTimePToDateTimeString(snap.CreatedAt),
148+
snaplockExpiryTime,
143149
)
144150
}
145151

internal/cmd/beta/sfs/snapshot/list/list_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package list
33
import (
44
"context"
55
"testing"
6+
"time"
67

78
"github.com/google/go-cmp/cmp"
89
"github.com/google/go-cmp/cmp/cmpopts"
@@ -12,6 +13,7 @@ import (
1213
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1517
)
1618

1719
var projectIdFlag = globalflags.ProjectIdFlag
@@ -160,6 +162,22 @@ func TestOutputResult(t *testing.T) {
160162
},
161163
wantErr: false,
162164
},
165+
{
166+
name: "set full snapshot",
167+
args: args{
168+
resp: []sfs.ResourcePoolSnapshot{
169+
{
170+
SnapshotName: utils.Ptr("name"),
171+
ResourcePoolId: utils.Ptr("rp-id"),
172+
SizeGigabytes: utils.Ptr(int32(10)),
173+
LogicalSizeGigabytes: utils.Ptr(int32(8)),
174+
CreatedAt: utils.Ptr(time.Now()),
175+
SnaplockExpiryTime: *sfs.NewNullableTime(utils.Ptr(time.Now().Add(time.Hour))),
176+
},
177+
},
178+
},
179+
wantErr: false,
180+
},
163181
}
164182
params := testparams.NewTestParams()
165183

internal/cmd/beta/sfs/snapshot/update/update.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func outputResult(p *print.Printer, outputFormat, snapshotLabel, resourcePoolLab
146146
snapshotLabel,
147147
resourcePoolLabel,
148148
)
149+
150+
if resp.ResourcePoolSnapshot.SnaplockExpiryTime.IsSet() && resp.ResourcePoolSnapshot.SnaplockExpiryTime.Get() != nil {
151+
p.Outputf("Snaplock expiry time: %s\n", utils.ConvertTimePToDateTimeString(resp.ResourcePoolSnapshot.SnaplockExpiryTime.Get()))
152+
}
153+
149154
return nil
150155
})
151156
}

internal/cmd/beta/sfs/snapshot/update/update_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package update
33
import (
44
"context"
55
"testing"
6+
"time"
67

78
"github.com/google/go-cmp/cmp"
89
"github.com/google/go-cmp/cmp/cmpopts"
@@ -235,6 +236,17 @@ func TestOutputResult(t *testing.T) {
235236
},
236237
wantErr: false,
237238
},
239+
{
240+
name: "set snaplock expiry time",
241+
args: args{
242+
resp: &sfs.UpdateResourcePoolSnapshotResponse{
243+
ResourcePoolSnapshot: &sfs.ResourcePoolSnapshot{
244+
SnaplockExpiryTime: *sfs.NewNullableTime(utils.Ptr(time.Now())),
245+
},
246+
},
247+
},
248+
wantErr: false,
249+
},
238250
}
239251
params := testparams.NewTestParams()
240252

0 commit comments

Comments
 (0)