-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rakshit Gondwal <[email protected]>
- Loading branch information
1 parent
100e2fa
commit e1e33e9
Showing
3 changed files
with
162 additions
and
58 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
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,80 @@ | ||
package builddocker | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEditDockerFile(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
lines []string | ||
isDev bool | ||
tag string | ||
expectedRes []string | ||
expectError bool | ||
}{ | ||
{ | ||
name: "Dev", | ||
lines: []string{ | ||
"FROM ubuntu:18.04 # bsfimage:dev", | ||
"RUN apt-get update", | ||
}, | ||
isDev: true, | ||
tag: "latest", | ||
expectedRes: []string{ | ||
"FROM ubuntu:latest # bsfimage:dev", | ||
"RUN apt-get update", | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "Runtime", | ||
lines: []string{ | ||
"FROM ubuntu:18.04 # bsfimage:runtime", | ||
"RUN apt-get update", | ||
}, | ||
isDev: false, | ||
tag: "latest", | ||
expectedRes: []string{ | ||
"FROM ubuntu:latest # bsfimage:runtime", | ||
"RUN apt-get update", | ||
}, | ||
expectError: false, | ||
}, | ||
{ | ||
name: "No FROM Command with bsf tag", | ||
lines: []string{ | ||
"FROM ubuntu:latest", | ||
"RUN apt-get update", | ||
}, | ||
isDev: true, | ||
tag: "latest", | ||
expectedRes: nil, | ||
expectError: true, | ||
}, | ||
{ | ||
name: "No FROM Command", | ||
lines: []string{ | ||
"RUN apt-get update", | ||
}, | ||
isDev: true, | ||
tag: "latest", | ||
expectedRes: nil, | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
res, err := editDockerfile(tt.lines, tt.isDev, tt.tag) | ||
if tt.expectError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.expectedRes, res) | ||
} | ||
}) | ||
} | ||
} |