* add test * return validation error not nil from function Reviewed-on: https://gitea.com/gitea/act_runner/pulls/683 Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com> Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Co-committed-by: Christopher Homberger <christopher.homberger@web.de> (cherry picked from commit f0b5aff3bbeda469a682fe21144c16485ea2189a) <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/647): <!--number 647 --><!--line 0 --><!--description ZmVhdDogZmFpbCB3aGVuIHVzaW5nIGFuIGludmFsaWQgbGFiZWwgZHVyaW5nIG5vbiBpbnRlcmFjdGl2ZSByZWdpc3RyYXRpb24=-->feat: fail when using an invalid label during non interactive registration<!--description--> <!--end release-notes-assistant--> Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/647 Reviewed-by: Gusted <gusted@noreply.code.forgejo.org> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
42 lines
989 B
Go
42 lines
989 B
Go
// Copyright 2025 The Forgejo Authors
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCommaSplit(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
expected []string
|
|
}{
|
|
{"", []string{}},
|
|
{"abc", []string{"abc"}},
|
|
{"abc,def", []string{"abc", "def"}},
|
|
{"abc, def", []string{"abc", "def"}},
|
|
{" abc , def ", []string{"abc", "def"}},
|
|
{"abc, ,def", []string{"abc", "def"}},
|
|
{" , , ", []string{}},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
result := commaSplit(test.input)
|
|
if !slices.Equal(result, test.expected) {
|
|
t.Errorf("commaSplit(%q) = %v, want %v", test.input, result, test.expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRegisterNonInteractiveReturnsLabelValidationError(t *testing.T) {
|
|
err := registerNoInteractive(t.Context(), "", ®isterArgs{
|
|
Labels: "label:invalid",
|
|
Token: "token",
|
|
InstanceAddr: "http://localhost:3000",
|
|
})
|
|
assert.Error(t, err, "unsupported schema: invalid")
|
|
}
|