Skip to content

Commit

Permalink
refactor: solve cyclic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Jan 9, 2024
1 parent 344fbf3 commit 1ffa0dc
Show file tree
Hide file tree
Showing 112 changed files with 439 additions and 339 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewCommand(s state.State) *cobra.Command {
DisableFlagsInUseLine: true,
}
cmd.AddCommand(
listCmd.CobraCommand(s),
ListCmd.CobraCommand(s),
)
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/all/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var allCmds = []base.ListCmd{
sshkey.ListCmd,
}

var listCmd = base.Cmd{
var ListCmd = base.Cmd{
BaseCobraCommand: func(client hcapi2.Client) *cobra.Command {

var resources []string
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/all/list_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package all
package all_test

import (
_ "embed"
Expand All @@ -9,6 +9,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/all"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -22,7 +23,7 @@ func TestListAll(t *testing.T) {

time.Local = time.UTC

cmd := listCmd.CobraCommand(fx.State())
cmd := all.ListCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.ServerClient.EXPECT().
Expand Down Expand Up @@ -246,7 +247,7 @@ func TestListAllPaidJSON(t *testing.T) {

time.Local = time.UTC

cmd := listCmd.CobraCommand(fx.State())
cmd := all.ListCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.ServerClient.EXPECT().
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/certificate/create_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package certificate
package certificate_test

import (
_ "embed"
Expand All @@ -8,6 +8,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/certificate"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -22,7 +23,7 @@ func TestCreateManaged(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := CreateCmd.CobraCommand(fx.State())
cmd := certificate.CreateCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestCreateManagedJSON(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := CreateCmd.CobraCommand(fx.State())
cmd := certificate.CreateCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand Down Expand Up @@ -104,7 +105,7 @@ func TestCreateUploaded(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := CreateCmd.CobraCommand(fx.State())
cmd := certificate.CreateCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand Down Expand Up @@ -132,7 +133,7 @@ func TestCreateUploadedJSON(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := CreateCmd.CobraCommand(fx.State())
cmd := certificate.CreateCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/certificate/delete_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package certificate
package certificate_test

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/certificate"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -14,7 +15,7 @@ func TestDelete(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := DeleteCmd.CobraCommand(fx.State())
cmd := certificate.DeleteCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

cert := &hcloud.Certificate{
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/certificate/describe_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package certificate
package certificate_test

import (
"fmt"
Expand All @@ -9,6 +9,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/certificate"
"github.com/hetznercloud/cli/internal/cmd/util"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
Expand All @@ -20,7 +21,7 @@ func TestDescribe(t *testing.T) {

time.Local = time.UTC

cmd := DescribeCmd.CobraCommand(fx.State())
cmd := certificate.DescribeCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

cert := &hcloud.Certificate{
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/certificate/labels_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package certificate
package certificate_test

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/certificate"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -14,7 +15,7 @@ func TestLabelAdd(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := LabelCmds.AddCobraCommand(fx.State())
cmd := certificate.LabelCmds.AddCobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand All @@ -39,7 +40,7 @@ func TestLabelRemove(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := LabelCmds.RemoveCobraCommand(fx.State())
cmd := certificate.LabelCmds.RemoveCobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/certificate/list_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package certificate
package certificate_test

import (
"testing"
Expand All @@ -7,6 +7,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/certificate"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -17,7 +18,7 @@ func TestList(t *testing.T) {

time.Local = time.UTC

cmd := ListCmd.CobraCommand(fx.State())
cmd := certificate.ListCmd.CobraCommand(fx.State())

fx.ExpectEnsureToken()
fx.Client.CertificateClient.EXPECT().
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/certificate/update_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package certificate
package certificate_test

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/certificate"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -14,7 +15,7 @@ func TestUpdateName(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := UpdateCmd.CobraCommand(fx.State())
cmd := certificate.UpdateCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.CertificateClient.EXPECT().
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/datacenter/describe_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package datacenter
package datacenter_test

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/datacenter"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -14,7 +15,7 @@ func TestDescribe(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := DescribeCmd.CobraCommand(fx.State())
cmd := datacenter.DescribeCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

fx.Client.DatacenterClient.EXPECT().
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/datacenter/list_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datacenter
package datacenter_test

import (
"testing"
Expand All @@ -7,6 +7,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/datacenter"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -17,7 +18,7 @@ func TestList(t *testing.T) {

time.Local = time.UTC

cmd := ListCmd.CobraCommand(fx.State())
cmd := datacenter.ListCmd.CobraCommand(fx.State())

fx.ExpectEnsureToken()
fx.Client.DatacenterClient.EXPECT().
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/firewall/add_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var AddRuleCmd = base.Cmd{
case hcloud.FirewallRuleDirectionOut:
rule.DestinationIPs = make([]net.IPNet, len(destinationIPs))
for i, ip := range destinationIPs {
n, err := validateFirewallIP(ip)
n, err := ValidateFirewallIP(ip)
if err != nil {
return fmt.Errorf("destination error on index %d: %s", i, err)
}
Expand All @@ -96,7 +96,7 @@ var AddRuleCmd = base.Cmd{
case hcloud.FirewallRuleDirectionIn:
rule.SourceIPs = make([]net.IPNet, len(sourceIPs))
for i, ip := range sourceIPs {
n, err := validateFirewallIP(ip)
n, err := ValidateFirewallIP(ip)
if err != nil {
return fmt.Errorf("source ips error on index %d: %s", i, err)
}
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/firewall/add_rule_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package firewall
package firewall_test

import (
"net"
Expand All @@ -7,6 +7,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/firewall"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -15,19 +16,19 @@ func TestAddRule(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := AddRuleCmd.CobraCommand(fx.State())
cmd := firewall.AddRuleCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

firewall := &hcloud.Firewall{
fw := &hcloud.Firewall{
ID: 123,
Name: "test",
}

fx.Client.FirewallClient.EXPECT().
Get(gomock.Any(), "test").
Return(firewall, nil, nil)
Return(fw, nil, nil)
fx.Client.FirewallClient.EXPECT().
SetRules(gomock.Any(), firewall, hcloud.FirewallSetRulesOpts{
SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{
Rules: []hcloud.FirewallRule{{
Direction: hcloud.FirewallRuleDirectionIn,
SourceIPs: []net.IPNet{{IP: net.IP{0, 0, 0, 0}, Mask: net.IPMask{0, 0, 0, 0}}},
Expand Down
19 changes: 10 additions & 9 deletions internal/cmd/firewall/apply_to_resource_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package firewall
package firewall_test

import (
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/hetznercloud/cli/internal/cmd/firewall"
"github.com/hetznercloud/cli/internal/testutil"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)
Expand All @@ -14,22 +15,22 @@ func TestApplyToServer(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := ApplyToResourceCmd.CobraCommand(fx.State())
cmd := firewall.ApplyToResourceCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

firewall := &hcloud.Firewall{
fw := &hcloud.Firewall{
ID: 123,
Name: "test",
}

fx.Client.FirewallClient.EXPECT().
Get(gomock.Any(), "test").
Return(firewall, nil, nil)
Return(fw, nil, nil)
fx.Client.ServerClient.EXPECT().
Get(gomock.Any(), "my-server").
Return(&hcloud.Server{ID: 456}, nil, nil)
fx.Client.FirewallClient.EXPECT().
ApplyResources(gomock.Any(), firewall, []hcloud.FirewallResource{{
ApplyResources(gomock.Any(), fw, []hcloud.FirewallResource{{
Type: hcloud.FirewallResourceTypeServer,
Server: &hcloud.FirewallResourceServer{
ID: 456,
Expand All @@ -52,19 +53,19 @@ func TestApplyToLabelSelector(t *testing.T) {
fx := testutil.NewFixture(t)
defer fx.Finish()

cmd := ApplyToResourceCmd.CobraCommand(fx.State())
cmd := firewall.ApplyToResourceCmd.CobraCommand(fx.State())
fx.ExpectEnsureToken()

firewall := &hcloud.Firewall{
fw := &hcloud.Firewall{
ID: 123,
Name: "test",
}

fx.Client.FirewallClient.EXPECT().
Get(gomock.Any(), "test").
Return(firewall, nil, nil)
Return(fw, nil, nil)
fx.Client.FirewallClient.EXPECT().
ApplyResources(gomock.Any(), firewall, []hcloud.FirewallResource{{
ApplyResources(gomock.Any(), fw, []hcloud.FirewallResource{{
Type: hcloud.FirewallResourceTypeLabelSelector,
LabelSelector: &hcloud.FirewallResourceLabelSelector{
Selector: "my-label",
Expand Down
Loading

0 comments on commit 1ffa0dc

Please sign in to comment.