Skip to content

Commit

Permalink
Add deprecation notice for old config style
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonTClipp committed Jul 8, 2023
1 parent 7a91185 commit c064f2b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 18 deletions.
23 changes: 6 additions & 17 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ func (r *RootApp) Run() error {
if err != nil {
return fmt.Errorf("failed to get package from config: %w", err)
}
warnBeta(
ctx,
"use of the 'packages' config variable is currently in a beta state. Use at your own risk.",
map[string]any{
"discussion": "https://github.com/vektra/mockery/discussions/549",
})
parser := pkg.NewParser(buildTags)

if err := parser.ParsePackages(ctx, configuredPackages); err != nil {
Expand Down Expand Up @@ -311,13 +305,12 @@ func (r *RootApp) Run() error {
log.Fatal().Msgf("Use --name to specify the name of the interface or --all for all interfaces found")
}

infoDiscussion(
warnDeprecated(
ctx,
"dynamic walking of project is being considered for removal "+
"in v3. Please provide your feedback at the linked discussion.",
"use of the packages config will be the only way to generate mocks in v3. Please migrate your config to use the packages feature.",
map[string]any{
"pr": "https://github.com/vektra/mockery/pull/548",
"discussion": "https://github.com/vektra/mockery/discussions/549",
"url": logging.DocsURL("/features/#packages-configuration"),
"migration": logging.DocsURL("/migrating_to_packages/"),
})

if r.Config.Profile != "" {
Expand Down Expand Up @@ -422,10 +415,6 @@ func info(ctx context.Context, prefix string, message string, fields map[string]
event.Msgf("%s: %s", prefix, message)
}

func infoDiscussion(ctx context.Context, message string, fields map[string]any) {
info(ctx, "DISCUSSION", message, fields)
}

func warnBeta(ctx context.Context, message string, fields map[string]any) {
warn(ctx, "BETA FEATURE", message, fields)
func warnDeprecated(ctx context.Context, message string, fields map[string]any) {
warn(ctx, "DEPRECATION", message, fields)
}
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (c *Config) subPackages(
if currentDepth == 0 && len(pkg.GoFiles) == 0 {
log.Error().
Err(ErrNoGoFilesFoundInRoot).
Str("documentation", "https://vektra.github.io/mockery/latest/notes/#error-no-go-files-found-in-root-search-path").
Str("documentation", logging.DocsURL("/notes/#error-no-go-files-found-in-root-search-path")).
Msg("package contains no go files")
return nil, ErrNoGoFilesFoundInRoot
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package logging

import (
"errors"
"fmt"
"os"
"runtime/debug"
"strings"
"time"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -39,6 +41,23 @@ func GetSemverInfo() string {
return _defaultSemVer
}

func getMinorSemver(semver string) string {
split := strings.Split(semver, ".")
return strings.Join(split[0:2], ".")
}

// GetMinorSemver returns the semantic version up to and including the minor version.
func GetMinorSemver() string {
return getMinorSemver(GetSemverInfo())
}

func DocsURL(relativePath string) string {
if string(relativePath[0]) != "/" {
relativePath = "/" + relativePath
}
return fmt.Sprintf("https://vektra.github.io/mockery/%s%s", GetMinorSemver(), relativePath)
}

type timeHook struct{}

func (t timeHook) Run(e *zerolog.Event, level zerolog.Level, msg string) {
Expand Down
62 changes: 62 additions & 0 deletions pkg/logging/logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package logging

import (
"testing"
)

func Test_getMinorSemver(t *testing.T) {
tests := []struct {
name string
arg string
want string
}{
{
name: "default semver",
arg: "v0.0.0-dev",
want: "v0.0",
},
{
name: "example semver",
arg: "v2.0.1",
want: "v2.0",
},
{
name: "example semver with alpha notation",
arg: "v3.0.0-alpha.0",
want: "v3.0",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getMinorSemver(tt.arg); got != tt.want {
t.Errorf("getMinorSemver() = %v, want %v", got, tt.want)
}
})
}
}

func TestDocsURL(t *testing.T) {
tests := []struct {
name string
arg string
want string
}{
{
name: "url with no leading slash",
arg: "features",
want: "https://vektra.github.io/mockery/v0.0/features",
},
{
name: "url with leading slash",
arg: "/features",
want: "https://vektra.github.io/mockery/v0.0/features",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DocsURL(tt.arg); got != tt.want {
t.Errorf("DocsURL() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit c064f2b

Please sign in to comment.