Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCR: Add support for multiple-registry open beta endpoints #1611

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions commands/command_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type CmdConfig struct {
Kubernetes func() do.KubernetesService
Databases func() do.DatabasesService
Registry func() do.RegistryService
Registries func() do.RegistriesService
VPCs func() do.VPCsService
OneClicks func() do.OneClickService
Apps func() do.AppsService
Expand Down Expand Up @@ -118,6 +119,7 @@ func NewCmdConfig(ns string, dc doctl.Config, out io.Writer, args []string, init
c.Kubernetes = func() do.KubernetesService { return do.NewKubernetesService(godoClient) }
c.Databases = func() do.DatabasesService { return do.NewDatabasesService(godoClient) }
c.Registry = func() do.RegistryService { return do.NewRegistryService(godoClient) }
c.Registries = func() do.RegistriesService { return do.NewRegistriesService(godoClient) }
c.VPCs = func() do.VPCsService { return do.NewVPCsService(godoClient) }
c.OneClicks = func() do.OneClickService { return do.NewOneClickService(godoClient) }
c.Apps = func() do.AppsService { return do.NewAppsService(godoClient) }
Expand Down
3 changes: 3 additions & 0 deletions commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ type tcMocks struct {
projects *domocks.MockProjectsService
kubernetes *domocks.MockKubernetesService
registry *domocks.MockRegistryService
registries *domocks.MockRegistriesService
sshRunner *domocks.MockRunner
vpcs *domocks.MockVPCsService
oneClick *domocks.MockOneClickService
Expand Down Expand Up @@ -220,6 +221,7 @@ func withTestClient(t *testing.T, tFn testFn) {
kubernetes: domocks.NewMockKubernetesService(ctrl),
databases: domocks.NewMockDatabasesService(ctrl),
registry: domocks.NewMockRegistryService(ctrl),
registries: domocks.NewMockRegistriesService(ctrl),
sshRunner: domocks.NewMockRunner(ctrl),
vpcs: domocks.NewMockVPCsService(ctrl),
oneClick: domocks.NewMockOneClickService(ctrl),
Expand Down Expand Up @@ -279,6 +281,7 @@ func withTestClient(t *testing.T, tFn testFn) {
Kubernetes: func() do.KubernetesService { return tm.kubernetes },
Databases: func() do.DatabasesService { return tm.databases },
Registry: func() do.RegistryService { return tm.registry },
Registries: func() do.RegistriesService { return tm.registries },
VPCs: func() do.VPCsService { return tm.vpcs },
OneClicks: func() do.OneClickService { return tm.oneClick },
Apps: func() do.AppsService { return tm.apps },
Expand Down
1 change: 1 addition & 0 deletions commands/doit.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func addCommands() {
DoitCmd.AddCommand(Projects())
DoitCmd.AddCommand(Version())
DoitCmd.AddCommand(Registry())
DoitCmd.AddCommand(Registries())
DoitCmd.AddCommand(VPCs())
DoitCmd.AddCommand(OneClicks())
DoitCmd.AddCommand(Monitoring())
Expand Down
316 changes: 289 additions & 27 deletions commands/registry.go

Large diffs are not rendered by default.

204 changes: 204 additions & 0 deletions commands/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,3 +1085,207 @@ func TestGetAvailableRegions(t *testing.T) {
})
})
}

func TestRegistriesCreate(t *testing.T) {
t.Run("success", func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
rcr := godo.RegistriesCreateRequest{
Name: testRegistryName,
Region: testRegistryRegion,
}
tm.registries.EXPECT().Create(&rcr).Return(&testRegistry, nil)
config.Args = append(config.Args, testRegistryName)
config.Doit.Set(config.NS, doctl.ArgRegionSlug, testRegistryRegion)

config.Registries = func() do.RegistriesService {
return tm.registries
}

err := RunRegistriesCreate(config)
assert.NoError(t, err)
})
})

t.Run("region omitted", func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
rcr := godo.RegistriesCreateRequest{
Name: testRegistryName,
}
tm.registries.EXPECT().Create(&rcr).Return(&testRegistry, nil)
config.Args = append(config.Args, testRegistryName)

config.Registries = func() do.RegistriesService {
return tm.registries
}

err := RunRegistriesCreate(config)
assert.NoError(t, err)
})
})

t.Run("error", func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
rcr := godo.RegistriesCreateRequest{
Name: testRegistryName,
Region: testRegistryRegion,
}
tm.registries.EXPECT().Create(&rcr).Return(nil, errTest)
config.Args = append(config.Args, testRegistryName)
config.Doit.Set(config.NS, doctl.ArgRegionSlug, testRegistryRegion)

config.Registries = func() do.RegistriesService {
return tm.registries
}

err := RunRegistriesCreate(config)
assert.Error(t, err)
assert.Equal(t, errTest, err)
})
})
}

func TestRegistriesGet(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.registries.EXPECT().Get(testRegistryName).Return(&testRegistry, nil)

config.Args = append(config.Args, testRegistryName)
config.Registries = func() do.RegistriesService {
return tm.registries
}

var buf bytes.Buffer
config.Out = &buf
err := RunRegistriesGet(config)
assert.NoError(t, err)
output := buf.String()
assert.Contains(t, output, testRegistry.Name)
})
}

func TestRegistriesDelete(t *testing.T) {
t.Run("success", func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.registries.EXPECT().Delete(testRegistryName).Return(nil)

config.Args = append(config.Args, testRegistryName)
config.Doit.Set(config.NS, doctl.ArgForce, true)

config.Registries = func() do.RegistriesService {
return tm.registries
}

err := RunRegistriesDelete(config)
assert.NoError(t, err)
})
})

t.Run("error", func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.registries.EXPECT().Delete(testRegistryName).Return(errTest)

config.Args = append(config.Args, testRegistryName)
config.Doit.Set(config.NS, doctl.ArgForce, true)

config.Registries = func() do.RegistriesService {
return tm.registries
}

err := RunRegistriesDelete(config)
assert.Error(t, err)
assert.Equal(t, errTest, err)
})
})
}

func TestRegistriesDockerConfig(t *testing.T) {
tests := []struct {
name string
readWrite bool
expirySeconds int
expect func(m *mocks.MockRegistriesService)
}{
{
name: "read-only-no-expiry",
readWrite: false,
expirySeconds: 0,
expect: func(m *mocks.MockRegistriesService) {
m.EXPECT().DockerCredentials(testRegistryName, &godo.RegistryDockerCredentialsRequest{
ReadWrite: false,
}).Return(testDockerCredentials, nil)
},
},
{
name: "read-write-no-expiry",
readWrite: true,
expirySeconds: 0,
expect: func(m *mocks.MockRegistriesService) {
m.EXPECT().DockerCredentials(testRegistryName, &godo.RegistryDockerCredentialsRequest{
ReadWrite: true,
}).Return(testDockerCredentials, nil)
},
},
{
name: "read-only-with-expiry",
readWrite: false,
expirySeconds: 3600,
expect: func(m *mocks.MockRegistriesService) {
m.EXPECT().DockerCredentials(testRegistryName, &godo.RegistryDockerCredentialsRequest{
ReadWrite: false,
ExpirySeconds: godo.PtrTo(3600),
}).Return(testDockerCredentials, nil)
},
},
{
name: "read-write-with-expiry",
readWrite: true,
expirySeconds: 3600,
expect: func(m *mocks.MockRegistriesService) {
m.EXPECT().DockerCredentials(testRegistryName, &godo.RegistryDockerCredentialsRequest{
ReadWrite: true,
ExpirySeconds: godo.PtrTo(3600),
}).Return(testDockerCredentials, nil)
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
if test.expect != nil {
test.expect(tm.registries)
}

config.Args = append(config.Args, testRegistryName)
config.Doit.Set(config.NS, doctl.ArgReadWrite, test.readWrite)
config.Doit.Set(config.NS, doctl.ArgRegistryExpirySeconds, test.expirySeconds)

config.Registries = func() do.RegistriesService {
return tm.registries
}

var output bytes.Buffer
config.Out = &output

err := RunRegistriesDockerConfig(config)
assert.NoError(t, err)

expectedOutput := append(testDockerCredentials.DockerConfigJSON, '\n')
assert.Equal(t, expectedOutput, output.Bytes())
})
})
}
}

func TestRegistriesList(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.registries.EXPECT().List().Return([]do.Registry{testRegistry}, nil)

var buf bytes.Buffer
config.Out = &buf
err := RunRegistriesList(config)
assert.NoError(t, err)

output := buf.String()
assert.Contains(t, output, testRegistry.Name)
})
}
1 change: 1 addition & 0 deletions do/mocks/AccountService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/ActionService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/AppsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/BalanceService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/BillingHistoryService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/CDNsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/CertificatesService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/DatabasesService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/DomainService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/DropletActionService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/FirewallsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/ImageActionsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/ImageService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/InvoicesService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/KeysService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/KubernetesService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/Listen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions do/mocks/LoadBalancersService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading