Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions internal/cmd/ske/cluster/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package create
import (
"context"
"testing"
"time"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
Expand Down Expand Up @@ -60,8 +61,8 @@ var testPayload = &ske.CreateOrUpdateClusterPayload{
MachineImageVersion: utils.Ptr(true),
},
TimeWindow: &ske.TimeWindow{
End: utils.Ptr("0000-01-01T05:00:00+02:00"),
Start: utils.Ptr("0000-01-01T03:00:00+02:00"),
End: utils.Ptr(time.Date(0000, 01, 01, 5, 0, 0, 0, time.UTC)),
Start: utils.Ptr(time.Date(0000, 01, 01, 3, 0, 0, 0, time.UTC)),
},
},
}
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/ske/cluster/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package update
import (
"context"
"testing"
"time"

"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
Expand Down Expand Up @@ -60,8 +61,8 @@ var testPayload = ske.CreateOrUpdateClusterPayload{
MachineImageVersion: utils.Ptr(true),
},
TimeWindow: &ske.TimeWindow{
End: utils.Ptr("0000-01-01T05:00:00+02:00"),
Start: utils.Ptr("0000-01-01T03:00:00+02:00"),
End: utils.Ptr(time.Date(0000, 01, 01, 5, 0, 0, 0, time.UTC)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a matter of personal style I prefer something like this:

func mustDateParse(fmt, val string) time.Time {
	time, err := time.Parse(fmt, val)
	if err != nil {
		log.Panicf("cannot parse %q with format %q: %v", val, fmt, err)
	}
	return time
}
...
			End:   utils.Ptr(mustDateParse(time.RFC3339, "0000-01-01T05:00:00+02:00")),

but the current one is totally correct

Start: utils.Ptr(time.Date(0000, 01, 01, 3, 0, 0, 0, time.UTC)),
},
},
}
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/ske/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/goccy/go-yaml"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
Expand Down Expand Up @@ -238,7 +239,7 @@ func buildKubernetesVersionsTable(resp *ske.ProviderOptions) (tables.Table, erro
}
expirationDate := ""
if v.ExpirationDate != nil {
expirationDate = *v.ExpirationDate
expirationDate = v.ExpirationDate.Format(time.RFC3339)
}
table.AddRow(*v.Version, *v.State, expirationDate, string(featureGate))
}
Expand All @@ -265,7 +266,7 @@ func buildMachineImagesTable(resp *ske.ProviderOptions) tables.Table {

expirationDate := "-"
if version.ExpirationDate != nil {
expirationDate = *version.ExpirationDate
expirationDate = version.ExpirationDate.Format(time.RFC3339)
}
table.AddRow(*image.Name, *version.Version, *version.State, expirationDate, criNamesString)
}
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/services/ske/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const (
)

type SKEClient interface {
GetServiceStatusExecute(ctx context.Context, projectId string) (*ske.ProjectResponse, error)
ListClustersExecute(ctx context.Context, projectId string) (*ske.ListClustersResponse, error)
ListProviderOptionsExecute(ctx context.Context) (*ske.ProviderOptions, error)
}
Expand Down
14 changes: 0 additions & 14 deletions internal/pkg/services/ske/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/ske"
)

Expand Down Expand Up @@ -65,25 +64,12 @@ users:
)

type skeClientMocked struct {
serviceDisabled bool
getServiceStatusFails bool
getServiceStatusResp *ske.ProjectResponse
listClustersFails bool
listClustersResp *ske.ListClustersResponse
listProviderOptionsFails bool
listProviderOptionsResp *ske.ProviderOptions
}

func (m *skeClientMocked) GetServiceStatusExecute(_ context.Context, _ string) (*ske.ProjectResponse, error) {
if m.getServiceStatusFails {
return nil, fmt.Errorf("could not get service status")
}
if m.serviceDisabled {
return nil, &oapierror.GenericOpenAPIError{StatusCode: 404}
}
return m.getServiceStatusResp, nil
}

func (m *skeClientMocked) ListClustersExecute(_ context.Context, _ string) (*ske.ListClustersResponse, error) {
if m.listClustersFails {
return nil, fmt.Errorf("could not list clusters")
Expand Down