-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add release markers * release info * add assertions for mocks expectations * add comment for isNoSuchKeyError * new lines missing
- Loading branch information
1 parent
38da340
commit 4b7720c
Showing
10 changed files
with
1,225 additions
and
11 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
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,59 @@ | ||
package release | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
type ReleaseInfo struct { | ||
AppName string `json:"app_name"` | ||
Tag string `json:"tag"` | ||
RunID string `json:"run_id"` | ||
RepoName string `json:"repo_name"` | ||
Schema string `json:"schema"` | ||
SchemaURL string `json:"schema_url"` | ||
} | ||
|
||
// Mark represents a release mark. It will contain the name of the release (appName, tag...) | ||
// and the start and end of a release | ||
// When the release has been started, the end will be zero | ||
type Mark struct { | ||
ReleaseInfo | ||
Start CustomTime `json:"start"` | ||
End CustomTime `json:"end"` | ||
} | ||
|
||
// Marker abstracts the persistence of the start and end of a release | ||
type Marker interface { | ||
Start(releaseInfo ReleaseInfo) (Mark, error) | ||
End(mark Mark) error | ||
} | ||
|
||
// CustomTime is a wrapper around time.Time that | ||
// allows to marshal and unmarshal time.Time in a custom format | ||
type CustomTime struct { | ||
time.Time | ||
} | ||
|
||
const ctLayout = time.RFC3339 | ||
|
||
func (ct *CustomTime) UnmarshalJSON(b []byte) error { | ||
var s string | ||
if err := json.Unmarshal(b, &s); err != nil { | ||
return err | ||
} | ||
t, err := time.Parse(ctLayout, s) | ||
if err != nil { | ||
return err | ||
} | ||
ct.Time = t | ||
return nil | ||
} | ||
|
||
func (ct *CustomTime) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(ct.Time.Format(ctLayout)) | ||
} | ||
|
||
func (ct *CustomTime) Equals(t CustomTime) bool { | ||
return ct.Truncate(time.Second).Equal(t.Truncate(time.Second)) | ||
} |
Oops, something went wrong.