44 "archive/tar"
55 "bytes"
66 "context"
7+ "fmt"
78 "io"
89 "os"
910 "testing"
@@ -16,8 +17,11 @@ var testContext = zerolog.New(os.Stdout).With().Timestamp().Logger().WithContext
1617
1718func TestCreateIfNotExists (t * testing.T ) {
1819 fs := afero.Afero {Fs : afero .NewMemMapFs ()}
19- if _ , err := fs .Stat ("apppack.toml" ); ! os .IsNotExist (err ) {
20- t .Error ("apppack.toml should not exist" )
20+
21+ filename := GetAppPackTomlFilename ()
22+
23+ if _ , err := fs .Stat (filename ); ! os .IsNotExist (err ) {
24+ t .Error (fmt .Sprintf ("%s should not exist" , filename ))
2125 }
2226 s := & FileState {
2327 fs : fs ,
@@ -27,8 +31,8 @@ func TestCreateIfNotExists(t *testing.T) {
2731 if err != nil {
2832 t .Error (err )
2933 }
30- if _ , err := fs .Stat ("apppack.toml" ); os .IsNotExist (err ) {
31- t .Error ("apppack.toml should exist" )
34+ if _ , err := fs .Stat (filename ); os .IsNotExist (err ) {
35+ t .Error (fmt . Sprintf ( "%s should exist", filename ) )
3236 }
3337}
3438
@@ -105,6 +109,27 @@ func TestWriteEnvFile(t *testing.T) {
105109 }
106110}
107111
112+ func TestGetFilename (t * testing.T ) {
113+ // Check that there is no env variable set
114+ if os .Getenv ("APPPACK_TOML" ) != "" {
115+ t .Error ("APPPACK_TOML env variable should not be set" )
116+ }
117+ // Call GetAppPackTomlFilename and check the default value
118+
119+ filename := GetAppPackTomlFilename ()
120+ if filename != "apppack.toml" {
121+ t .Errorf ("expected apppack.toml, got %s" , filename )
122+ }
123+
124+ // Set the env variable and check again
125+ os .Setenv ("APPPACK_TOML" , "custom.toml" )
126+ defer os .Unsetenv ("APPPACK_TOML" ) // Clean up after the test
127+ filename = GetAppPackTomlFilename ()
128+ if filename != "custom.toml" {
129+ t .Errorf ("expected custom.toml, got %s" , filename )
130+ }
131+ }
132+
108133func dummyTarBuffer () (* io.Reader , error ) {
109134 var buf bytes.Buffer
110135 tw := tar .NewWriter (& buf )
0 commit comments