0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-09-21 08:12:44 +02:00
wp-plugin-go/plugin/commit_test.go
renovate[bot] 796cbec0da
chore(deps): update dependency golangci/golangci-lint to v1.56.1 (#56)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
2024-02-12 09:25:15 +01:00

79 lines
1.6 KiB
Go

package plugin
import (
"context"
"testing"
"github.com/urfave/cli/v2"
)
func Test_currFromContext(t *testing.T) {
tests := []struct {
envs map[string]string
want map[string]string
}{
{
envs: map[string]string{
"CI_COMMIT_MESSAGE": "",
},
want: map[string]string{
"title": "",
"desc": "",
"message": "",
},
},
{
envs: map[string]string{
"CI_COMMIT_MESSAGE": "test_title\ntest_desc",
},
want: map[string]string{
"title": "test_title",
"desc": "test_desc",
"message": "test_title\ntest_desc",
},
},
{
envs: map[string]string{
"CI_COMMIT_MESSAGE": "test_title\ntest_desc\nadditional",
},
want: map[string]string{
"title": "test_title",
"desc": "test_desc\nadditional",
"message": "test_title\ntest_desc\nadditional",
},
},
}
for _, tt := range tests {
for key, value := range tt.envs {
t.Setenv(key, value)
}
options := Options{
Name: "dummy",
Execute: func(_ context.Context) error { return nil },
}
got := New(options)
got.App.Action = func(ctx *cli.Context) error {
got.Metadata = MetadataFromContext(ctx)
return nil
}
_ = got.App.Run([]string{"dummy"})
if got.Metadata.Curr.Message != tt.want["message"] {
t.Errorf("got = %q, want = %q", got.Metadata.Curr.Message, tt.want["message"])
}
if got.Metadata.Curr.Title != tt.want["title"] {
t.Errorf("got = %q, want = %q", got.Metadata.Curr.Title, tt.want["title"])
}
if got.Metadata.Curr.Description != tt.want["desc"] {
t.Errorf("got = %q, want = %q", got.Metadata.Curr.Description, tt.want["desc"])
}
}
}