-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(file): Add config, adjust tests
Signed-off-by: Bence Csati <[email protected]>
- Loading branch information
Showing
5 changed files
with
91 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package file | ||
|
||
import "os" | ||
|
||
const ( | ||
EnvPrefix = "FILE_" | ||
DefaultMountPath = "/" | ||
) | ||
|
||
type Config struct { | ||
MountPath string `json:"mountPath"` | ||
} | ||
|
||
func NewConfig() *Config { | ||
mountPath, ok := os.LookupEnv(EnvPrefix + "MOUNT_PATH") | ||
if !ok { | ||
mountPath = DefaultMountPath | ||
} | ||
|
||
return &Config{MountPath: mountPath} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package file | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
env map[string]string | ||
wantMountPath string | ||
}{ | ||
{ | ||
name: "Default mount path", | ||
env: map[string]string{}, | ||
wantMountPath: "/", | ||
}, | ||
{ | ||
name: "Custom mount path", | ||
env: map[string]string{ | ||
"FILE_MOUNT_PATH": "test/secrets", | ||
}, | ||
wantMountPath: "test/secrets", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
ttp := tt | ||
t.Run(ttp.name, func(t *testing.T) { | ||
for envKey, envVal := range ttp.env { | ||
os.Setenv(envKey, envVal) | ||
} | ||
|
||
config := NewConfig() | ||
if config.MountPath != ttp.wantMountPath { | ||
t.Errorf("NewConfig() = %v, wantMountPath %v", config.MountPath, ttp.wantMountPath) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters