-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e318fcb
commit 4f9b5e4
Showing
88 changed files
with
1,480 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
dist/ | ||
/dist/ | ||
/Dockerfile |
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
This file was deleted.
Oops, something went wrong.
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
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,100 @@ | ||
package runtime_test | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/flexstack/new-dockerfile/runtime" | ||
) | ||
|
||
func TestBunMatch(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
expected bool | ||
}{ | ||
{ | ||
name: "Bun project", | ||
path: "../testdata/bun", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Bun project with .ts file", | ||
path: "../testdata/bun-bunfig", | ||
expected: true, | ||
}, | ||
{ | ||
name: "Not a Bun project", | ||
path: "../testdata/deno", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
bun := &runtime.Bun{Log: logger} | ||
if bun.Match(test.path) != test.expected { | ||
t.Errorf("expected %v, got %v", test.expected, bun.Match(test.path)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestBunGenerateDockerfile(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
expected []any | ||
}{ | ||
{ | ||
name: "Bun project", | ||
path: "../testdata/bun", | ||
expected: []any{`ARG VERSION=1`, `ARG INSTALL_CMD="bun install"`, regexp.MustCompile(`^ARG BUILD_CMD=$`), `ARG START_CMD="bun index.ts"`}, | ||
}, | ||
{ | ||
name: "Bun project with .ts file", | ||
path: "../testdata/bun-bunfig", | ||
expected: []any{`ARG VERSION=1.1.4`, `ARG INSTALL_CMD="bun install"`, `ARG BUILD_CMD="bun run build:prod"`, `ARG START_CMD="bun run start:production"`}, | ||
}, | ||
{ | ||
name: "Not a Bun project", | ||
path: "../testdata/deno", | ||
expected: []any{`ARG VERSION=1`, regexp.MustCompile(`^ARG INSTALL_CMD="bun install"`), regexp.MustCompile(`^ARG BUILD_CMD=$`), regexp.MustCompile(`^ARG START_CMD=$`)}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
bun := &runtime.Bun{Log: logger} | ||
dockerfile, err := bun.GenerateDockerfile(test.path) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
for _, line := range test.expected { | ||
found := false | ||
lines := strings.Split(string(dockerfile), "\n") | ||
|
||
for _, l := range lines { | ||
switch v := line.(type) { | ||
case string: | ||
if strings.Contains(l, v) { | ||
found = true | ||
break | ||
} | ||
case *regexp.Regexp: | ||
if v.MatchString(l) { | ||
found = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
if !found { | ||
t.Errorf("expected %v, not found in %v", line, string(dockerfile)) | ||
} | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.