-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add include property to GitRepositories
Signed-off-by: Philip Laine <philip.laine@gmail.com>
- Loading branch information
1 parent
de775f6
commit 0c13ff8
Showing
12 changed files
with
746 additions
and
274 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
package controllers | ||
|
||
import sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" | ||
|
||
// hasArtifactUpdated returns true if any of the revisions in the current artifacts | ||
// does not match any of the artifacts in the updated artifacts | ||
func hasArtifactUpdated(current []*sourcev1.Artifact, updated []*sourcev1.Artifact) bool { | ||
if len(current) != len(updated) { | ||
return true | ||
} | ||
|
||
OUTER: | ||
for _, c := range current { | ||
for _, u := range updated { | ||
if u.HasRevision(c.Revision) { | ||
continue OUTER | ||
} | ||
} | ||
return true | ||
} | ||
|
||
return false | ||
} |
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,110 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" | ||
) | ||
|
||
func TestHasUpdated(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
current []*sourcev1.Artifact | ||
updated []*sourcev1.Artifact | ||
expected bool | ||
}{ | ||
{ | ||
name: "not updated single", | ||
current: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
}, | ||
updated: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "updated single", | ||
current: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
}, | ||
updated: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "bar", | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "not updated multiple", | ||
current: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
{ | ||
Revision: "bar", | ||
}, | ||
}, | ||
updated: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
{ | ||
Revision: "bar", | ||
}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "updated multiple", | ||
current: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
{ | ||
Revision: "bar", | ||
}, | ||
}, | ||
updated: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
{ | ||
Revision: "baz", | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "updated different artifact count", | ||
current: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
{ | ||
Revision: "bar", | ||
}, | ||
}, | ||
updated: []*sourcev1.Artifact{ | ||
{ | ||
Revision: "foo", | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := hasArtifactUpdated(tt.current, tt.updated) | ||
if result != tt.expected { | ||
t.Errorf("Archive() result = %v, wantResult %v", result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.