Skip to content

Commit

Permalink
Replace abslute path in .golden file to make the test portable
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward J committed Jun 14, 2024
1 parent 4e420c4 commit eaa6d73
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/pkg/cli/loader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"bytes"
"context"
"os"
"path/filepath"
Expand All @@ -21,16 +22,21 @@ func TestLoader(t *testing.T) {
if err != nil {
t.Fatal(err)
}
bytes, err := proj.MarshalYAML()
yaml, err := proj.MarshalYAML()
if err != nil {
t.Fatal(err)
}

// Replace the absolute path in context to make the .golden file portable
absPath, _ := filepath.Abs(path)
yaml = bytes.ReplaceAll(yaml, []byte(filepath.Dir(absPath)), []byte("TESTPATH"))

golden, err := os.ReadFile(path + ".golden")
if err != nil {
os.WriteFile(path+".golden", bytes, 0644)
} else if string(bytes) != string(golden) {
os.WriteFile(path+".golden", yaml, 0644)
} else if string(yaml) != string(golden) {
t.Errorf("Result mismatch, written as %s.mismatch", path)
os.WriteFile(path+".mismatch", bytes, 0644)
os.WriteFile(path+".mismatch", yaml, 0644)
}
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion src/tests/alttestproj/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: tests
services:
dfnx:
build:
context: /home/edw/defang/defang/src/tests/alttestproj
context: TESTPATH
dockerfile: Dockerfile
args:
DNS: dfnx
Expand Down
2 changes: 1 addition & 1 deletion src/tests/emptyenv/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: emptyenv
services:
emptyenv:
build:
context: /home/edw/defang/defang/src/tests/emptyenv
context: TESTPATH
dockerfile: Dockerfile
args:
ARG2: ""
Expand Down
2 changes: 1 addition & 1 deletion src/tests/secretname/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: secretname
services:
app:
build:
context: /home/edw/defang/defang/src/tests/secretname
context: TESTPATH
dockerfile: Dockerfile
networks:
default: null
Expand Down
2 changes: 1 addition & 1 deletion src/tests/testproj/compose.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: tests
services:
dfnx:
build:
context: /home/edw/defang/defang/src/tests/testproj
context: TESTPATH
dockerfile: Dockerfile
args:
DNS: dfnx
Expand Down

0 comments on commit eaa6d73

Please sign in to comment.