Skip to content

Commit

Permalink
refactor: test management optimization (#268)
Browse files Browse the repository at this point in the history
Co-authored-by: jzli <[email protected]>
  • Loading branch information
kinsolee and jzli authored Sep 2, 2022
1 parent 302060e commit 5af16c0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apis/data/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/meta/v1alpha1/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
ErrorReason = "Error"
// StartedReason resource started to be reconciled
StartedReason = "Started"
// BlockedReason a testPlan was blocked
BlockedReason = "Blocked"
)

const (
Expand Down
22 changes: 22 additions & 0 deletions apis/meta/v1alpha1/testcaseexecution_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package v1alpha1

import (
"regexp"
"strings"

authv1 "k8s.io/api/authorization/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -79,3 +82,22 @@ func TestCaseExecutionResourceAttributes(verb string) authv1.ResourceAttributes
Verb: verb,
}
}

func UserSpecFromNote(note string) *UserSpec {
if note == "" {
return nil
}

reg, _ := regexp.Compile("\\[createdBy: ([\\w@.\\-_]*\\|[\\w@.\\-_]*)]")
matches := reg.FindStringSubmatch(note)
if len(matches) > 1 {
splits := strings.Split(matches[1], "|")
if len(splits) == 2 {
return &UserSpec{
Name: splits[0],
Email: splits[1],
}
}
}
return nil
}
74 changes: 74 additions & 0 deletions apis/meta/v1alpha1/testcaseexecution_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package v1alpha1

import (
"reflect"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
authv1 "k8s.io/api/authorization/v1"
Expand All @@ -34,3 +37,74 @@ var _ = Describe("TestCaseExecution", func() {
})
})
})

func Test_executorFromNote(t *testing.T) {
tests := []struct {
name string
note string
want *UserSpec
}{
{
name: "empty string",
note: "",
want: nil,
},
{
name: "invalid string format",
note: "xxxxxx",
want: nil,
},
{
name: "invalid user string",
note: "[createdBy: xxx!!!xxx]",
want: nil,
},
{
name: "valid user string",
note: "[createdBy: xxx|[email protected]]",
want: &UserSpec{
Name: "xxx",
Email: "[email protected]",
},
},
{
name: "allow email is not valid",
note: "[createdBy: xxx|xxxxx]",
want: &UserSpec{
Name: "xxx",
Email: "xxxxx",
},
},
{
name: "allow email is empty",
note: "[createdBy: xxx|]",
want: &UserSpec{
Name: "xxx",
Email: "",
},
},
{
name: "allow both is empty",
note: "[createdBy: |]",
want: &UserSpec{
Name: "",
Email: "",
},
},
{
name: "allow both is empty",
note: "[createdBy: xiangmu@._-|xiangmu@-._]",
want: &UserSpec{
Name: "xiangmu@._-",
Email: "xiangmu@-._",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := UserSpecFromNote(tt.note); !reflect.DeepEqual(got, tt.want) {
t.Errorf("UserSpecFromNote() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 2 additions & 0 deletions apis/meta/v1alpha1/testplan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"knative.dev/pkg/apis"
)

const DefaultTestPlansPerPage = 20

var TestPlanGVK = GroupVersion.WithKind("TestPlan")
var TestPlanListGVK = GroupVersion.WithKind("TestPlanList")

Expand Down
2 changes: 1 addition & 1 deletion apis/meta/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5af16c0

Please sign in to comment.