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

[NET-9152] CRD for service registeration #3943

Merged
merged 19 commits into from
May 7, 2024
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
Next Next commit
first test for to catalog registration type
  • Loading branch information
jm96441n committed May 1, 2024
commit ae7f13ca8144ac1ad591a84a58d4fc94a1895dbe
54 changes: 54 additions & 0 deletions control-plane/api/v1alpha1/registration_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package v1alpha1

import (
"testing"

capi "github.com/hashicorp/consul/api"

"github.com/stretchr/testify/require"
)

func TestToCatalogRegistration(tt *testing.T) {
cases := map[string]struct {
registration *Registration
expected *capi.CatalogRegistration
}{
"minimal registration": {
registration: &Registration{
Spec: RegistrationSpec{
ID: "node-id",
Node: "node-virtual",
Address: "127.0.0.1",
Datacenter: "dc1",
Service: Service{
ID: "service-id",
Name: "service-name",
Port: 8080,
Address: "127.0.0.1",
},
},
},
expected: &capi.CatalogRegistration{
ID: "node-id",
Node: "node-virtual",
Address: "127.0.0.1",
Datacenter: "dc1",
Service: &capi.AgentService{
ID: "service-id",
Service: "service-name",
Port: 8080,
Address: "127.0.0.1",
},
},
},
}

for name, tc := range cases {
tc := tc
tt.Run(name, func(t *testing.T) {
t.Parallel()
actual := tc.registration.ToCatalogRegistration()
require.Equal(t, tc.expected, actual)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

for name, tc := range cases {
tt.Run(name, func(t *testing.T) {
t.Parallel()
s := runtime.NewScheme()
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.Registration{})
ctx := context.Background()
Expand All @@ -115,7 +116,7 @@
Watcher: test.MockConnMgrForIPAndPort(t, host, port, false),
}

fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(tc.registration).Build()

Check failure on line 119 in control-plane/controllers/configentries/registrations_controller_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

loopclosure: loop variable tc captured by func literal (govet)

controller := &configentries.RegistrationsController{
Client: fakeClient,
Expand All @@ -126,12 +127,12 @@
}

_, err = controller.Reconcile(ctx, ctrl.Request{
NamespacedName: types.NamespacedName{Name: tc.registration.Name, Namespace: tc.registration.Namespace},

Check failure on line 130 in control-plane/controllers/configentries/registrations_controller_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

loopclosure: loop variable tc captured by func literal (govet)
})
require.NoError(t, err)

fetchedReg := &v1alpha1.Registration{TypeMeta: metav1.TypeMeta{APIVersion: "consul.hashicorp.com/v1alpha1", Kind: "Registration"}}
fakeClient.Get(ctx, types.NamespacedName{Name: tc.registration.Name}, fetchedReg)

Check failure on line 135 in control-plane/controllers/configentries/registrations_controller_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

loopclosure: loop variable tc captured by func literal (govet)

require.Len(t, fetchedReg.Status.Conditions, len(tc.expectedConditions))

Expand Down Expand Up @@ -215,6 +216,7 @@

for name, tc := range cases {
tt.Run(name, func(t *testing.T) {
t.Parallel()
s := runtime.NewScheme()
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.Registration{})
ctx := context.Background()
Expand Down
Loading