-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(secret): use allow event system (#341)
* enhance(secret): use allow event system * fix some typos and linter changes * remove repo version of 'Allowed'
- Loading branch information
Showing
14 changed files
with
512 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ const ( | |
AllowDeployCreate | ||
AllowCommentCreate | ||
AllowCommentEdit | ||
AllowSchedule | ||
) |
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,53 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package actions | ||
|
||
import "github.com/go-vela/types/constants" | ||
|
||
// Schedule is the library representation of the various actions associated | ||
// with the schedule event. | ||
type Schedule struct { | ||
Run *bool `json:"run"` | ||
} | ||
|
||
// FromMask returns the Schedule type resulting from the provided integer mask. | ||
func (a *Schedule) FromMask(mask int64) *Schedule { | ||
a.SetRun(mask&constants.AllowSchedule > 0) | ||
|
||
return a | ||
} | ||
|
||
// ToMask returns the integer mask of the values for the Schedule set. | ||
func (a *Schedule) ToMask() int64 { | ||
mask := int64(0) | ||
|
||
if a.GetRun() { | ||
mask = mask | constants.AllowSchedule | ||
} | ||
|
||
return mask | ||
} | ||
|
||
// GetRun returns the Run field from the provided Schedule. If the object is nil, | ||
// or the field within the object is nil, it returns the zero value instead. | ||
func (a *Schedule) GetRun() bool { | ||
// return zero value if Schedule type or Run field is nil | ||
if a == nil || a.Run == nil { | ||
return false | ||
} | ||
|
||
return *a.Run | ||
} | ||
|
||
// SetRun sets the Schedule Run field. | ||
// | ||
// When the provided Schedule type is nil, it | ||
// will set nothing and immediately return. | ||
func (a *Schedule) SetRun(v bool) { | ||
// return if Schedule type is nil | ||
if a == nil { | ||
return | ||
} | ||
|
||
a.Run = &v | ||
} |
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,98 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package actions | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/go-vela/types/constants" | ||
) | ||
|
||
func TestLibrary_Schedule_Getters(t *testing.T) { | ||
// setup tests | ||
tests := []struct { | ||
actions *Schedule | ||
want *Schedule | ||
}{ | ||
{ | ||
actions: testSchedule(), | ||
want: testSchedule(), | ||
}, | ||
{ | ||
actions: new(Schedule), | ||
want: new(Schedule), | ||
}, | ||
} | ||
|
||
// run tests | ||
for _, test := range tests { | ||
if test.actions.GetRun() != test.want.GetRun() { | ||
t.Errorf("GetRun is %v, want %v", test.actions.GetRun(), test.want.GetRun()) | ||
} | ||
} | ||
} | ||
|
||
func TestLibrary_Schedule_Setters(t *testing.T) { | ||
// setup types | ||
var a *Schedule | ||
|
||
// setup tests | ||
tests := []struct { | ||
actions *Schedule | ||
want *Schedule | ||
}{ | ||
{ | ||
actions: testSchedule(), | ||
want: testSchedule(), | ||
}, | ||
{ | ||
actions: a, | ||
want: new(Schedule), | ||
}, | ||
} | ||
|
||
// run tests | ||
for _, test := range tests { | ||
test.actions.SetRun(test.want.GetRun()) | ||
|
||
if test.actions.GetRun() != test.want.GetRun() { | ||
t.Errorf("SetRun is %v, want %v", test.actions.GetRun(), test.want.GetRun()) | ||
} | ||
} | ||
} | ||
|
||
func TestLibrary_Schedule_FromMask(t *testing.T) { | ||
// setup types | ||
mask := testMask() | ||
|
||
want := testSchedule() | ||
|
||
// run test | ||
got := new(Schedule).FromMask(mask) | ||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("FromMask is %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestLibrary_Schedule_ToMask(t *testing.T) { | ||
// setup types | ||
actions := testSchedule() | ||
|
||
want := int64(constants.AllowSchedule) | ||
|
||
// run test | ||
got := actions.ToMask() | ||
|
||
if want != got { | ||
t.Errorf("ToMask is %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func testSchedule() *Schedule { | ||
schedule := new(Schedule) | ||
schedule.SetRun(true) | ||
|
||
return schedule | ||
} |
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.