-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move trustroot resync period configration to different package
Signed-off-by: Meredith Lancaster <[email protected]>
- Loading branch information
Showing
7 changed files
with
60 additions
and
43 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,24 @@ | ||
package tuf | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"knative.dev/pkg/controller" | ||
) | ||
|
||
type trustrootResyncPeriodKey struct{} | ||
|
||
func ToContext(ctx context.Context, duration time.Duration) context.Context { | ||
return context.WithValue(ctx, trustrootResyncPeriodKey{}, duration) | ||
} | ||
|
||
// FromContextOrDefaults returns a stored trustrootResyncPeriod if attached. | ||
// If not found, it returns a default duration | ||
func FromContextOrDefaults(ctx context.Context) time.Duration { | ||
x, ok := ctx.Value(trustrootResyncPeriodKey{}).(time.Duration) | ||
if ok { | ||
return x | ||
} | ||
return controller.DefaultResyncPeriod | ||
} |
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,27 @@ | ||
package tuf | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"knative.dev/pkg/controller" | ||
rtesting "knative.dev/pkg/reconciler/testing" | ||
) | ||
|
||
func TestContextDuration(t *testing.T) { | ||
ctx, _ := rtesting.SetupFakeContext(t) | ||
|
||
expected := controller.DefaultResyncPeriod | ||
actual := FromContextOrDefaults(ctx) | ||
if expected != actual { | ||
t.Fatal("Expected the context to store the value and be retrievable") | ||
} | ||
|
||
expected = time.Hour | ||
ctx = ToContext(ctx, expected) | ||
actual = FromContextOrDefaults(ctx) | ||
|
||
if expected != actual { | ||
t.Fatal("Expected the context to store the value and be retrievable") | ||
} | ||
} |
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