Skip to content

Commit

Permalink
fix: Renamed parameter to better communicate usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yiannistri committed Jul 25, 2023
1 parent 9df8319 commit 28e4418
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions core/fluxsync/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type SourceRef interface {
Namespace() string
}

// Automation objects are Kustomizations and HelmReleases.
// These are the only object types that can be triggered
// to be reconciled with their source.
type Automation interface {
Reconcilable
SourceRef() SourceRef
Expand Down
40 changes: 20 additions & 20 deletions core/server/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,84 +61,84 @@ func TestSync(t *testing.T) {
g.Expect(k.Create(ctx, ociRepo)).Should(Succeed())

tests := []struct {
name string
msg *pb.SyncFluxObjectRequest
automation fluxsync.Reconcilable
source fluxsync.Reconcilable
name string
msg *pb.SyncFluxObjectRequest
reconcilable fluxsync.Reconcilable
source fluxsync.Reconcilable
}{{
name: "helm release no source",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: helmv2.HelmReleaseKind}},
WithSource: false,
},
automation: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
reconcilable: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
}, {
name: "helm release with source",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: helmv2.HelmReleaseKind}},
WithSource: true,
},
automation: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
reconcilable: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
}, {
name: "kustomization no source",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: kustomizev1.KustomizationKind}},
WithSource: false,
},
automation: fluxsync.KustomizationAdapter{Kustomization: kust},
reconcilable: fluxsync.KustomizationAdapter{Kustomization: kust},
}, {
name: "kustomization with source",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: kustomizev1.KustomizationKind}},
WithSource: true,
},
automation: fluxsync.KustomizationAdapter{Kustomization: kust},
source: fluxsync.NewReconcileable(gitRepo),
reconcilable: fluxsync.KustomizationAdapter{Kustomization: kust},
source: fluxsync.NewReconcileable(gitRepo),
}, {
name: "gitrepository",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: sourcev1.GitRepositoryKind}},
WithSource: false,
},
automation: fluxsync.GitRepositoryAdapter{GitRepository: gitRepo},
reconcilable: fluxsync.GitRepositoryAdapter{GitRepository: gitRepo},
}, {
name: "bucket",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: sourcev1.BucketKind}},
WithSource: false,
},
automation: fluxsync.BucketAdapter{Bucket: bucket},
reconcilable: fluxsync.BucketAdapter{Bucket: bucket},
}, {
name: "helmchart",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: sourcev1.HelmChartKind}},
WithSource: false,
},
automation: fluxsync.HelmChartAdapter{HelmChart: chart},
reconcilable: fluxsync.HelmChartAdapter{HelmChart: chart},
}, {
name: "helmrepository",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: sourcev1.HelmRepositoryKind}},
WithSource: false,
},
automation: fluxsync.HelmRepositoryAdapter{HelmRepository: helmRepo},
reconcilable: fluxsync.HelmRepositoryAdapter{HelmRepository: helmRepo},
}, {
name: "ocirepository",
msg: &pb.SyncFluxObjectRequest{
Objects: []*pb.ObjectRef{{ClusterName: "Default",
Kind: sourcev1.OCIRepositoryKind}},
WithSource: false,
},
automation: fluxsync.OCIRepositoryAdapter{OCIRepository: ociRepo},
reconcilable: fluxsync.OCIRepositoryAdapter{OCIRepository: ociRepo},
}, {
name: "multiple objects",
msg: &pb.SyncFluxObjectRequest{
Expand All @@ -147,16 +147,16 @@ func TestSync(t *testing.T) {
Kind: helmv2.HelmReleaseKind}},
WithSource: true,
},
automation: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
reconcilable: fluxsync.HelmReleaseAdapter{HelmRelease: hr},
source: fluxsync.NewReconcileable(helmRepo),
}}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
msg := tt.msg
for _, msg := range msg.Objects {
msg.Name = tt.automation.GetName()
msg.Namespace = tt.automation.GetNamespace()
msg.Name = tt.reconcilable.GetName()
msg.Namespace = tt.reconcilable.GetNamespace()
}

done := make(chan error)
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestSync(t *testing.T) {
}

an := types.NamespacedName{Name: name, Namespace: ns.Name}
if err := simulateReconcile(ctx, k, an, tt.automation.AsClientObject()); err != nil {
if err := simulateReconcile(ctx, k, an, tt.reconcilable.AsClientObject()); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit 28e4418

Please sign in to comment.