-
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.
[MM-49202] Implement retention policy of failed jobs (#43)
* Implement retention policy of failed jobs * Update service/docker/service.go Co-authored-by: Christopher Poile <[email protected]> * Add custom validation to support days * Skip job if retention time is zero * Avoid custom type --------- Co-authored-by: Christopher Poile <[email protected]>
- Loading branch information
1 parent
d196e46
commit ab0e524
Showing
8 changed files
with
347 additions
and
17 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,69 @@ | ||
// Copyright (c) 2022-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
package service | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseRetentionTime(t *testing.T) { | ||
tcs := []struct { | ||
name string | ||
input string | ||
expected time.Duration | ||
err string | ||
}{ | ||
{ | ||
name: "invalid formatting", | ||
input: "10dd", | ||
expected: 0, | ||
err: "invalid retention time format", | ||
}, | ||
{ | ||
name: "mixed units", | ||
input: "10h10m", | ||
expected: 0, | ||
err: "invalid retention time format", | ||
}, | ||
{ | ||
name: "seconds", | ||
input: "45s", | ||
expected: 0, | ||
err: "invalid retention time format", | ||
}, | ||
{ | ||
name: "minutes", | ||
input: "45m", | ||
expected: time.Minute * 45, | ||
err: "", | ||
}, | ||
{ | ||
name: "hours", | ||
input: "24h", | ||
expected: time.Hour * 24, | ||
err: "", | ||
}, | ||
{ | ||
name: "days", | ||
input: "10d", | ||
expected: time.Hour * 24 * 10, | ||
err: "", | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
d, err := parseRetentionTime(tc.input) | ||
if tc.err != "" { | ||
require.EqualError(t, err, tc.err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
require.Equal(t, tc.expected, d) | ||
}) | ||
} | ||
} |
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.