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

Register resource-get for containeragent binary; #12906

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add test for RegisterForContainerAgent;
  • Loading branch information
ycliuhw committed Apr 21, 2021
commit 7ba01e7e3c820d527170934da89005e7a3f21304
14 changes: 10 additions & 4 deletions component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (
"github.com/juju/errors"
)

type component interface {
// run "go generate" from the package directory.
//go:generate go run github.com/golang/mock/mockgen -package all -destination component_mock.go github.com/juju/juju/component/all Component
type Component interface {
registerForServer() error
registerForClient() error
registerForContainerAgent() error
}

var components = []component{
var components = []Component{
&payloads{},
&resources{},
}
Expand All @@ -40,10 +42,14 @@ func RegisterForServer() error {
// RegisterForContainerAgent registers the parts of the components with the
// Juju machinery for use as a agent (e.g. jujud, jujuc).
func RegisterForContainerAgent() error {
components := []component{
components := []Component{
&resources{},
}
for _, c := range components {
return registerForContainerAgent(components)
}

func registerForContainerAgent(containerComponents []Component) error {
for _, c := range containerComponents {
if err := c.registerForContainerAgent(); err != nil {
return errors.Trace(err)
}
Expand Down
47 changes: 47 additions & 0 deletions component/all/all_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

// The all package facilitates the registration of Juju components into
// the relevant machinery. It is intended as the one place in Juju where
// the components (horizontal design layers) and the machinery
// (vertical/architectural layers) intersect. This approach helps
// alleviate interdependence between the components and the machinery.

package all

import (
"testing"

"github.com/golang/mock/gomock"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"

jujutesting "github.com/juju/juju/testing"
)

func Test(t *testing.T) {
gc.TestingT(t)
}

type allSuite struct {
jujutesting.BaseSuite
}

var _ = gc.Suite(&allSuite{})

func (s *allSuite) TestRegisterForContainerAgent(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()

resources := NewMockComponent(ctrl)
components := []Component{
resources,
}

gomock.InOrder(
resources.EXPECT().registerForContainerAgent().Return(nil),
)

err := registerForContainerAgent(components)
c.Assert(err, jc.ErrorIsNil)
}
75 changes: 75 additions & 0 deletions component/all/component_mock.go

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