Skip to content
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
5 changes: 2 additions & 3 deletions pkg/runtime/adoption_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package runtime_test
package runtime

import (
"context"
Expand All @@ -33,7 +33,6 @@ import (
ackmocks "github.com/aws-controllers-k8s/runtime/mocks/pkg/types"
ackcfg "github.com/aws-controllers-k8s/runtime/pkg/config"
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime"
ackrtcache "github.com/aws-controllers-k8s/runtime/pkg/runtime/cache"
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ func mockAdoptionReconciler() (acktypes.AdoptedResourceReconciler, *ctrlrtclient
sc.On("GetResourceManagerFactories").Return(rmFactoryMap)
kc := &ctrlrtclientmock.Client{}
apiReader := &ctrlrtclientmock.Reader{}
return ackrt.NewAdoptionReconcilerWithClient(
return NewAdoptionReconcilerWithClient(
sc,
fakeLogger,
cfg,
Expand Down
9 changes: 4 additions & 5 deletions pkg/runtime/field_export_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package runtime_test
package runtime

import (
"bytes"
Expand All @@ -35,7 +35,6 @@ import (
ackcfg "github.com/aws-controllers-k8s/runtime/pkg/config"
ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime"
ackrtcache "github.com/aws-controllers-k8s/runtime/pkg/runtime/cache"
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"

Expand Down Expand Up @@ -81,7 +80,7 @@ func mockFieldExportReconcilerWithResourceDescriptor(rd *mocks.AWSResourceDescri
sc.On("GetResourceManagerFactories").Return(rmFactoryMap)
kc := &ctrlrtclientmock.Client{}
apiReader := &ctrlrtclientmock.Reader{}
return ackrt.NewFieldExportReconcilerWithClient(
return NewFieldExportReconcilerWithClient(
sc,
fakeLogger,
cfg,
Expand Down Expand Up @@ -230,7 +229,7 @@ func setupMockUnstructuredConverter() {
}, nil,
)
// Update the package variable
ackrt.UnstructuredConverter = conv
UnstructuredConverter = conv
}

func mockSourceResource() (
Expand Down Expand Up @@ -594,7 +593,7 @@ func assertPatchedSecretWithKey(expected bool, t *testing.T, ctx context.Context
return bytes.Equal(val, []byte("test-book-name"))
})
if expected {
kc.AssertCalled(t, "Patch", withoutCancelContextMatcher, dataMatcher, mock.Anything)
kc.AssertCalled(t, "Patch", withoutCancelContextMatcher, dataMatcher, mock.Anything)
} else {
kc.AssertNotCalled(t, "Patch", withoutCancelContextMatcher, dataMatcher, mock.Anything)
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/runtime/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package runtime_test
package runtime

import (
"context"
Expand All @@ -29,7 +29,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sobj "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
k8srtschema "k8s.io/apimachinery/pkg/runtime/schema"
ctrlrtzap "sigs.k8s.io/controller-runtime/pkg/log/zap"

Expand All @@ -41,7 +40,6 @@ import (
"github.com/aws-controllers-k8s/runtime/pkg/featuregate"
ackmetrics "github.com/aws-controllers-k8s/runtime/pkg/metrics"
"github.com/aws-controllers-k8s/runtime/pkg/requeue"
ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime"
ackrtcache "github.com/aws-controllers-k8s/runtime/pkg/runtime/cache"
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"

Expand Down Expand Up @@ -125,7 +123,7 @@ func reconcilerMocks(
sc.On("GetMetadata").Return(scmd)
kc := &ctrlrtclientmock.Client{}

return ackrt.NewReconcilerWithClient(
return NewReconcilerWithClient(
sc, kc, rmf, fakeLogger, cfg, metrics, ackrtcache.Caches{},
), kc, scmd
}
Expand All @@ -150,7 +148,7 @@ func managerFactoryMocks(
) {
rd := &ackmocks.AWSResourceDescriptor{}
rd.On("GroupVersionKind").Return(
schema.GroupVersionKind{
k8srtschema.GroupVersionKind{
Group: "bookstore.services.k8s.aws",
Kind: "fakeBook",
},
Expand All @@ -164,7 +162,7 @@ func managerFactoryMocks(
rmf.On("ResourceDescriptor").Return(rd)
rmf.On("RequeueOnSuccessSeconds").Return(0)

reg := ackrt.NewRegistry()
reg := NewRegistry()
reg.RegisterResourceManagerFactory(rmf)
return rmf, rd
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/runtime/service_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package runtime_test
package runtime

import (
"context"
Expand Down Expand Up @@ -42,7 +42,6 @@ import (
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
mocks "github.com/aws-controllers-k8s/runtime/mocks/pkg/types"
ackcfg "github.com/aws-controllers-k8s/runtime/pkg/config"
ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime"
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
)

Expand Down Expand Up @@ -150,7 +149,7 @@ func TestServiceController(t *testing.T) {
rmf.On("ResourceDescriptor").Return(rd)
rmf.On("RequeueOnSuccessSeconds").Return(0)

reg := ackrt.NewRegistry()
reg := NewRegistry()
reg.RegisterResourceManagerFactory(rmf)

vi := acktypes.VersionInfo{
Expand All @@ -159,7 +158,7 @@ func TestServiceController(t *testing.T) {
BuildDate: "now",
}

sc := ackrt.NewServiceController("bookstore", "bookstore.services.k8s.aws", vi)
sc := NewServiceController("bookstore", "bookstore.services.k8s.aws", vi)
require.NotNil(sc)
zapOptions := ctrlrtzap.Options{
Development: true,
Expand Down
17 changes: 8 additions & 9 deletions pkg/runtime/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package runtime_test
package runtime

import (
"fmt"
Expand All @@ -21,7 +21,6 @@ import (

mocks "github.com/aws-controllers-k8s/runtime/mocks/controller-runtime/pkg/client"
"github.com/aws-controllers-k8s/runtime/pkg/config"
"github.com/aws-controllers-k8s/runtime/pkg/runtime"
acktags "github.com/aws-controllers-k8s/runtime/pkg/tags"
acktypes "github.com/aws-controllers-k8s/runtime/pkg/types"
)
Expand All @@ -42,27 +41,27 @@ func TestGetDefaultTags(t *testing.T) {
}

// nil config
assert.Empty(runtime.GetDefaultTags(nil, &obj, md))
assert.Empty(GetDefaultTags(nil, &obj, md))

// nil object
assert.Empty(runtime.GetDefaultTags(&cfg, nil, md))
assert.Empty(GetDefaultTags(&cfg, nil, md))

// no resource tags
assert.Empty(runtime.GetDefaultTags(&cfg, &obj, md))
assert.Empty(GetDefaultTags(&cfg, &obj, md))

// ill formed tags
cfg.ResourceTags = []string{"foobar"}
expandedTags := runtime.GetDefaultTags(&cfg, &obj, md)
expandedTags := GetDefaultTags(&cfg, &obj, md)
assert.Empty(expandedTags)

// ill formed tags
cfg.ResourceTags = []string{"foo=bar=baz"}
expandedTags = runtime.GetDefaultTags(&cfg, &obj, md)
expandedTags = GetDefaultTags(&cfg, &obj, md)
assert.Empty(expandedTags)

// tags without any ack resource tag format
cfg.ResourceTags = []string{"foo=bar"}
expandedTags = runtime.GetDefaultTags(&cfg, &obj, md)
expandedTags = GetDefaultTags(&cfg, &obj, md)
assert.Equal(1, len(expandedTags))
assert.Equal("bar", expandedTags["foo"])

Expand All @@ -80,7 +79,7 @@ func TestGetDefaultTags(t *testing.T) {
acktags.ResourceNameTagFormat,
),
}
expandedTags = runtime.GetDefaultTags(&cfg, &obj, md)
expandedTags = GetDefaultTags(&cfg, &obj, md)
assert.Equal(4, len(expandedTags))
assert.Equal("bar", expandedTags["foo"])
assert.Equal("s3-v0.0.10", expandedTags["services.k8s.aws/controller-version"])
Expand Down
21 changes: 10 additions & 11 deletions pkg/runtime/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package runtime_test
package runtime

import (
"testing"
Expand All @@ -21,7 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
ackrt "github.com/aws-controllers-k8s/runtime/pkg/runtime"

mocks "github.com/aws-controllers-k8s/runtime/mocks/pkg/types"
)
Expand All @@ -35,11 +34,11 @@ func TestIsAdopted(t *testing.T) {
ackv1alpha1.AnnotationAdopted: "true",
},
})
require.True(ackrt.IsAdopted(res))
require.True(IsAdopted(res))

res = &mocks.AWSResource{}
res.On("MetaObject").Return(&metav1.ObjectMeta{})
require.False(ackrt.IsAdopted(res))
require.False(IsAdopted(res))
}

func TestIsSynced(t *testing.T) {
Expand All @@ -52,7 +51,7 @@ func TestIsSynced(t *testing.T) {
Status: corev1.ConditionTrue,
},
})
require.True(ackrt.IsSynced(res))
require.True(IsSynced(res))

res = &mocks.AWSResource{}
res.On("Conditions").Return([]*ackv1alpha1.Condition{
Expand All @@ -65,7 +64,7 @@ func TestIsSynced(t *testing.T) {
Status: corev1.ConditionFalse,
},
})
require.False(ackrt.IsSynced(res))
require.False(IsSynced(res))
}

func TestIsForcedAdoption(t *testing.T) {
Expand All @@ -78,7 +77,7 @@ func TestIsForcedAdoption(t *testing.T) {
ackv1alpha1.AnnotationAdopted: "false",
},
})
require.True(ackrt.NeedAdoption(res))
require.True(NeedAdoption(res))

res = &mocks.AWSResource{}
res.On("MetaObject").Return(&metav1.ObjectMeta{
Expand All @@ -87,15 +86,15 @@ func TestIsForcedAdoption(t *testing.T) {
ackv1alpha1.AnnotationAdopted: "true",
},
})
require.False(ackrt.NeedAdoption(res))
require.False(NeedAdoption(res))

res = &mocks.AWSResource{}
res.On("MetaObject").Return(&metav1.ObjectMeta{
Annotations: map[string]string{
ackv1alpha1.AnnotationAdopted: "true",
ackv1alpha1.AnnotationAdopted: "true",
},
})
require.False(ackrt.NeedAdoption(res))
require.False(NeedAdoption(res))
}

func TestExtractAdoptionFields(t *testing.T) {
Expand All @@ -115,7 +114,7 @@ func TestExtractAdoptionFields(t *testing.T) {
"clusterName": "my-cluster",
"name": "ng-1234",
}
actual, err := ackrt.ExtractAdoptionFields(res)
actual, err := ExtractAdoptionFields(res)
require.NoError(err)
require.Equal(expected, actual)
}