Return error for non-existing runner group. (#2215)

This commit is contained in:
Tingluo Huang 2023-01-26 12:19:52 -05:00 committed by GitHub
parent 7ea60e497c
commit b09e3a2dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -300,7 +300,7 @@ func (c *Client) GetRunnerGroupByName(ctx context.Context, runnerGroup string) (
}
if runnerGroupList.Count == 0 {
return nil, nil
return nil, fmt.Errorf("no runner group found with name '%s'", runnerGroup)
}
if runnerGroupList.Count > 1 {

View File

@ -173,3 +173,47 @@ func TestDeleteRunner(t *testing.T) {
assert.Equalf(t, actualRetry, expectedRetry, "A retry was expected after the first request but got: %v", actualRetry)
})
}
func TestGetRunnerGroupByName(t *testing.T) {
ctx := context.Background()
auth := &actions.ActionsAuth{
Token: "token",
}
t.Run("Get RunnerGroup by Name", func(t *testing.T) {
var runnerGroupID int64 = 1
var runnerGroupName string = "test-runner-group"
want := &actions.RunnerGroup{
ID: runnerGroupID,
Name: runnerGroupName,
}
response := []byte(`{"count": 1, "value": [{"id": 1, "name": "test-runner-group"}]}`)
server := newActionsServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(response)
}))
client, err := actions.NewClient(ctx, server.configURLForOrg("my-org"), auth)
require.NoError(t, err)
got, err := client.GetRunnerGroupByName(ctx, runnerGroupName)
require.NoError(t, err)
assert.Equal(t, want, got)
})
t.Run("Get RunnerGroup by name with not exist runner group", func(t *testing.T) {
var runnerGroupName string = "test-runner-group"
response := []byte(`{"count": 0, "value": []}`)
server := newActionsServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(response)
}))
client, err := actions.NewClient(ctx, server.configURLForOrg("my-org"), auth)
require.NoError(t, err)
got, err := client.GetRunnerGroupByName(ctx, runnerGroupName)
assert.ErrorContains(t, err, "no runner group found with name")
assert.Nil(t, got)
})
}