-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix declared.Resources to be consistently ordered
- Resources' DeclaredUnstructureds, DeclaredObjects, DeclaredGVKs, and getObjectSet were previously iterating over a Go map, causing the output to be randomly ordered. This change replaces the map with an OrderedMap that can be iterated in insert order. This makes it easier to test classes that use declared.Resources, including Applier.Apply and parse.parseAndUpdate. - Add fakes for Applier, Remediator, and ConfigParser - Add test validation for Apply, Remediate, and Parse inputs and outputs - Fix fake.RootSync/RepoSync to avoid populating the status. These return a FileObject, which never have a status when created by the parser. - Fix filesystem.AsCoreObjects to return nil when empty - Replace kpt.dev/configsync/pkg/util/ordered with github.com/elliotchance/orderedmap/v2 which supports generics and actually has unit tests.
- Loading branch information
Showing
29 changed files
with
902 additions
and
982 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fake | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"kpt.dev/configsync/pkg/applier" | ||
"kpt.dev/configsync/pkg/status" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// Applier fakes applier.Applier. | ||
// | ||
// This is not in kpt.dev/configsync/pkg/testing/fake because that would cause | ||
// a import loop (applier -> fake -> applier). | ||
type Applier struct { | ||
ApplyInputs []ApplierInputs | ||
ApplyOutputs []ApplierOutputs | ||
|
||
ApplyCalls, ErrorsCalls int | ||
|
||
currentErrors status.MultiError | ||
} | ||
|
||
// ApplierInputs stores inputs for fake.Applier.Apply() | ||
type ApplierInputs struct { | ||
Objects []client.Object | ||
} | ||
|
||
// ApplierOutputs stores outputs for fake.Applier.Apply() | ||
type ApplierOutputs struct { | ||
Errors status.MultiError | ||
} | ||
|
||
// Apply fakes applier.Applier.Apply() | ||
func (a *Applier) Apply(_ context.Context, objects []client.Object) status.MultiError { | ||
a.ApplyInputs = append(a.ApplyInputs, ApplierInputs{ | ||
Objects: objects, | ||
}) | ||
if a.ApplyCalls >= len(a.ApplyOutputs) { | ||
panic(fmt.Sprintf("Expected only %d calls to Applier.Apply, but got more. Update Applier.ApplyOutputs if this is expected.", len(a.ApplyOutputs))) | ||
} | ||
outputs := a.ApplyOutputs[a.ApplyCalls] | ||
a.ApplyCalls++ | ||
a.currentErrors = outputs.Errors | ||
return outputs.Errors | ||
} | ||
|
||
// Errors fakes applier.Applier.Errors() | ||
func (a *Applier) Errors() status.MultiError { | ||
return a.currentErrors | ||
} | ||
|
||
var _ applier.Applier = &Applier{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.