test(featuredetection): add tests for ActionsFeatures
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
a0dea00fdd
commit
33825477ae
2 changed files with 78 additions and 0 deletions
|
|
@ -28,6 +28,10 @@ func (md *DisabledDetectorMock) ReleaseFeatures() (ReleaseFeatures, error) {
|
|||
return ReleaseFeatures{}, nil
|
||||
}
|
||||
|
||||
func (md *DisabledDetectorMock) ActionsFeatures() (ActionsFeatures, error) {
|
||||
return ActionsFeatures{}, nil
|
||||
}
|
||||
|
||||
type EnabledDetectorMock struct{}
|
||||
|
||||
func (md *EnabledDetectorMock) IssueFeatures() (IssueFeatures, error) {
|
||||
|
|
@ -56,6 +60,12 @@ func (md *EnabledDetectorMock) ReleaseFeatures() (ReleaseFeatures, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (md *EnabledDetectorMock) ActionsFeatures() (ActionsFeatures, error) {
|
||||
return ActionsFeatures{
|
||||
DispatchRunDetails: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type AdvancedIssueSearchDetectorMock struct {
|
||||
EnabledDetectorMock
|
||||
searchFeatures SearchFeatures
|
||||
|
|
|
|||
|
|
@ -696,3 +696,71 @@ func TestReleaseFeatures(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionsFeatures(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
hostname string
|
||||
httpStubs func(*httpmock.Registry)
|
||||
wantFeatures ActionsFeatures
|
||||
}{
|
||||
{
|
||||
name: "github.com, workflow dispatch run details supported",
|
||||
hostname: "github.com",
|
||||
wantFeatures: ActionsFeatures{
|
||||
DispatchRunDetails: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ghec data residency (ghe.com), workflow dispatch run details supported",
|
||||
hostname: "stampname.ghe.com",
|
||||
wantFeatures: ActionsFeatures{
|
||||
DispatchRunDetails: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "GHE 3.20, workflow dispatch run details not supported",
|
||||
hostname: "git.my.org",
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "api/v3/meta"),
|
||||
httpmock.StringResponse(`{"installed_version":"3.20.999"}`),
|
||||
)
|
||||
},
|
||||
wantFeatures: ActionsFeatures{
|
||||
DispatchRunDetails: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "GHE 3.21, workflow dispatch run details not supported",
|
||||
hostname: "git.my.org",
|
||||
httpStubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "api/v3/meta"),
|
||||
httpmock.StringResponse(`{"installed_version":"3.21.0"}`),
|
||||
)
|
||||
},
|
||||
wantFeatures: ActionsFeatures{
|
||||
DispatchRunDetails: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
reg := &httpmock.Registry{}
|
||||
if tt.httpStubs != nil {
|
||||
tt.httpStubs(reg)
|
||||
}
|
||||
httpClient := &http.Client{}
|
||||
httpmock.ReplaceTripper(httpClient, reg)
|
||||
|
||||
detector := NewDetector(httpClient, tt.hostname)
|
||||
|
||||
features, err := detector.ActionsFeatures()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tt.wantFeatures, features)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue