From 09cd270481acd94abdbd4dab06ab76144d09b2c2 Mon Sep 17 00:00:00 2001
From: Georgios Kampitakis <50364739+gkampitakis@users.noreply.github.com>
Date: Sat, 3 Aug 2024 08:33:21 +0100
Subject: [PATCH] fix: expose internal config type (#109)

---
 snaps/matchJSON.go               |  4 ++--
 snaps/matchSnapshot.go           |  4 ++--
 snaps/matchStandaloneSnapshot.go |  4 ++--
 snaps/snapshot.go                | 24 ++++++++++++------------
 snaps/snapshot_test.go           | 12 ++++++------
 snaps/utils.go                   |  2 +-
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/snaps/matchJSON.go b/snaps/matchJSON.go
index 0eea31f..10d78a7 100644
--- a/snaps/matchJSON.go
+++ b/snaps/matchJSON.go
@@ -34,7 +34,7 @@ validators or placeholders for data that might change on each invocation e.g. da
 
 	MatchJSON(t, User{created: time.Now(), email: "mock-email"}, match.Any("created"))
 */
-func (c *config) MatchJSON(t testingT, input any, matchers ...match.JSONMatcher) {
+func (c *Config) MatchJSON(t testingT, input any, matchers ...match.JSONMatcher) {
 	t.Helper()
 
 	matchJSON(c, t, input, matchers...)
@@ -60,7 +60,7 @@ func MatchJSON(t testingT, input any, matchers ...match.JSONMatcher) {
 	matchJSON(&defaultConfig, t, input, matchers...)
 }
 
-func matchJSON(c *config, t testingT, input any, matchers ...match.JSONMatcher) {
+func matchJSON(c *Config, t testingT, input any, matchers ...match.JSONMatcher) {
 	t.Helper()
 
 	snapPath, snapPathRel := snapshotPath(c, t.Name(), false)
diff --git a/snaps/matchSnapshot.go b/snaps/matchSnapshot.go
index 5a66ce4..b76cd9e 100644
--- a/snaps/matchSnapshot.go
+++ b/snaps/matchSnapshot.go
@@ -21,7 +21,7 @@ or call MatchSnapshot multiples times inside a test
 
 The difference is the latter will create multiple entries.
 */
-func (c *config) MatchSnapshot(t testingT, values ...any) {
+func (c *Config) MatchSnapshot(t testingT, values ...any) {
 	t.Helper()
 
 	matchSnapshot(c, t, values...)
@@ -46,7 +46,7 @@ func MatchSnapshot(t testingT, values ...any) {
 	matchSnapshot(&defaultConfig, t, values...)
 }
 
-func matchSnapshot(c *config, t testingT, values ...any) {
+func matchSnapshot(c *Config, t testingT, values ...any) {
 	t.Helper()
 
 	if len(values) == 0 {
diff --git a/snaps/matchStandaloneSnapshot.go b/snaps/matchStandaloneSnapshot.go
index 02aab97..6450193 100644
--- a/snaps/matchStandaloneSnapshot.go
+++ b/snaps/matchStandaloneSnapshot.go
@@ -16,7 +16,7 @@ MatchStandaloneSnapshot creates one snapshot file per call.
 You can call MatchStandaloneSnapshot multiple times inside a test.
 It will create multiple snapshot files at `__snapshots__` folder by default.
 */
-func (c *config) MatchStandaloneSnapshot(t testingT, value any) {
+func (c *Config) MatchStandaloneSnapshot(t testingT, value any) {
 	t.Helper()
 
 	matchStandaloneSnapshot(c, t, value)
@@ -38,7 +38,7 @@ func MatchStandaloneSnapshot(t testingT, value any) {
 	matchStandaloneSnapshot(&defaultConfig, t, value)
 }
 
-func matchStandaloneSnapshot(c *config, t testingT, value any) {
+func matchStandaloneSnapshot(c *Config, t testingT, value any) {
 	t.Helper()
 
 	genericPathSnap, genericSnapPathRel := snapshotPath(c, t.Name(), true)
diff --git a/snaps/snapshot.go b/snaps/snapshot.go
index 1feeebc..6466d5a 100644
--- a/snaps/snapshot.go
+++ b/snaps/snapshot.go
@@ -25,7 +25,7 @@ var (
 	updatedMsg = colors.Sprint(colors.Green, updateSymbol+"Snapshot updated")
 )
 
-type config struct {
+type Config struct {
 	filename  string
 	snapsDir  string
 	extension string
@@ -35,8 +35,8 @@ type config struct {
 // Update determines whether to update snapshots or not
 //
 // It respects if running on CI.
-func Update(u bool) func(*config) {
-	return func(c *config) {
+func Update(u bool) func(*Config) {
+	return func(c *Config) {
 		c.update = &u
 	}
 }
@@ -46,8 +46,8 @@ func Update(u bool) func(*config) {
 //	default: __snapshots__
 //
 // this doesn't change the file extension see `snap.Ext`
-func Filename(name string) func(*config) {
-	return func(c *config) {
+func Filename(name string) func(*Config) {
+	return func(c *Config) {
 		c.filename = name
 	}
 }
@@ -57,8 +57,8 @@ func Filename(name string) func(*config) {
 //	default: __snapshots__
 //
 // Accepts absolute paths
-func Dir(dir string) func(*config) {
-	return func(c *config) {
+func Dir(dir string) func(*Config) {
+	return func(c *Config) {
 		c.snapsDir = dir
 	}
 }
@@ -69,8 +69,8 @@ func Dir(dir string) func(*config) {
 //
 // Note: even if you specify a different extension the file still contain .snap
 // e.g. if you specify .txt the file will be .snap.txt
-func Ext(ext string) func(*config) {
-	return func(c *config) {
+func Ext(ext string) func(*Config) {
+	return func(c *Config) {
 		c.extension = ext
 	}
 }
@@ -78,7 +78,7 @@ func Ext(ext string) func(*config) {
 // Create snaps with configuration
 //
 //	e.g snaps.WithConfig(snaps.Filename("my_test")).MatchSnapshot(t, "hello world")
-func WithConfig(args ...func(*config)) *config {
+func WithConfig(args ...func(*Config)) *Config {
 	s := defaultConfig
 
 	for _, arg := range args {
@@ -313,7 +313,7 @@ func getPrevStandaloneSnapshot(snapPath string) (string, error) {
 //   - if it's standalone snapshot we also append an integer (_%d) in the filename (even before `.snap`)
 //
 // Returns the relative path of the caller and the snapshot path.
-func snapshotPath(c *config, tName string, isStandalone bool) (string, string) {
+func snapshotPath(c *Config, tName string, isStandalone bool) (string, string) {
 	//  skips current func, the wrapper match* and the exported Match* func
 	callerFilename := baseCaller(3)
 
@@ -328,7 +328,7 @@ func snapshotPath(c *config, tName string, isStandalone bool) (string, string) {
 	return snapPath, snapPathRel
 }
 
-func constructFilename(c *config, callerFilename, tName string, isStandalone bool) string {
+func constructFilename(c *Config, callerFilename, tName string, isStandalone bool) string {
 	filename := c.filename
 	if filename == "" {
 		base := filepath.Base(callerFilename)
diff --git a/snaps/snapshot_test.go b/snaps/snapshot_test.go
index 9298ede..4e6f9a6 100644
--- a/snaps/snapshot_test.go
+++ b/snaps/snapshot_test.go
@@ -204,7 +204,7 @@ func TestAddNewSnapshot(t *testing.T) {
 }
 
 func TestSnapshotPath(t *testing.T) {
-	snapshotPathWrapper := func(c *config, tName string, isStandalone bool) (snapPath, snapPathRel string) {
+	snapshotPathWrapper := func(c *Config, tName string, isStandalone bool) (snapPath, snapPathRel string) {
 		// This is for emulating being called from a func so we can find the correct file
 		// of the caller
 		func() {
@@ -224,7 +224,7 @@ func TestSnapshotPath(t *testing.T) {
 	})
 
 	t.Run("should return path and file from config", func(t *testing.T) {
-		snapPath, snapPathRel := snapshotPathWrapper(&config{
+		snapPath, snapPathRel := snapshotPathWrapper(&Config{
 			filename: "my_file",
 			snapsDir: "my_snapshot_dir",
 		}, "", false)
@@ -235,7 +235,7 @@ func TestSnapshotPath(t *testing.T) {
 	})
 
 	t.Run("should return absolute path", func(t *testing.T) {
-		snapPath, snapPathRel := snapshotPathWrapper(&config{
+		snapPath, snapPathRel := snapshotPathWrapper(&Config{
 			filename: "my_file",
 			snapsDir: "/path_to/my_snapshot_dir",
 		}, "", false)
@@ -250,7 +250,7 @@ func TestSnapshotPath(t *testing.T) {
 	})
 
 	t.Run("should add extension to filename", func(t *testing.T) {
-		snapPath, snapPathRel := snapshotPathWrapper(&config{
+		snapPath, snapPathRel := snapshotPathWrapper(&Config{
 			filename:  "my_file",
 			snapsDir:  "my_snapshot_dir",
 			extension: ".txt",
@@ -291,7 +291,7 @@ func TestSnapshotPath(t *testing.T) {
 	})
 
 	t.Run("should return standalone snapPath with overridden filename", func(t *testing.T) {
-		snapPath, snapPathRel := snapshotPathWrapper(&config{
+		snapPath, snapPathRel := snapshotPathWrapper(&Config{
 			filename: "my_file",
 			snapsDir: "my_snapshot_dir",
 		}, "my_test", true)
@@ -303,7 +303,7 @@ func TestSnapshotPath(t *testing.T) {
 	t.Run(
 		"should return standalone snapPath with overridden filename and extension",
 		func(t *testing.T) {
-			snapPath, snapPathRel := snapshotPathWrapper(&config{
+			snapPath, snapPathRel := snapshotPathWrapper(&Config{
 				filename:  "my_file",
 				snapsDir:  "my_snapshot_dir",
 				extension: ".txt",
diff --git a/snaps/utils.go b/snaps/utils.go
index 4cdbee4..ca279c6 100644
--- a/snaps/utils.go
+++ b/snaps/utils.go
@@ -19,7 +19,7 @@ var (
 	isCI            = ciinfo.IsCI
 	updateVAR       = os.Getenv("UPDATE_SNAPS")
 	shouldClean     = updateVAR == "true" || updateVAR == "clean"
-	defaultConfig   = config{
+	defaultConfig   = Config{
 		snapsDir: "__snapshots__",
 	}
 )