-
-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embedding libcompose types for yaml parsing (#495)
since github.com/docker/libcompose is deprecated, unmaintained and archived. and license is the same as woodpecker's, we can just copy stuff into woodpecker directly. (we only use types of that project anyway)
- Loading branch information
Showing
22 changed files
with
686 additions
and
549 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
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
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
5 changes: 3 additions & 2 deletions
5
...hub.com/docker/libcompose/yaml/command.go → pipeline/frontend/yaml/types/command.go
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,60 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type StructCommand struct { | ||
Entrypoint Command `yaml:"entrypoint,flow,omitempty"` | ||
Command Command `yaml:"command,flow,omitempty"` | ||
} | ||
|
||
func TestUnmarshalCommand(t *testing.T) { | ||
s := &StructCommand{} | ||
err := yaml.Unmarshal([]byte(`command: bash`), s) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, Command{"bash"}, s.Command) | ||
assert.Nil(t, s.Entrypoint) | ||
bytes, err := yaml.Marshal(s) | ||
assert.Nil(t, err) | ||
|
||
s2 := &StructCommand{} | ||
err = yaml.Unmarshal(bytes, s2) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, Command{"bash"}, s2.Command) | ||
assert.Nil(t, s2.Entrypoint) | ||
|
||
s3 := &StructCommand{} | ||
err = yaml.Unmarshal([]byte(`command: | ||
- echo AAA; echo "wow" | ||
- sleep 3s`), s3) | ||
assert.Nil(t, err) | ||
assert.Equal(t, Command{`echo AAA; echo "wow"`, `sleep 3s`}, s3.Command) | ||
} | ||
|
||
var sampleEmptyCommand = `{}` | ||
|
||
func TestUnmarshalEmptyCommand(t *testing.T) { | ||
s := &StructCommand{} | ||
err := yaml.Unmarshal([]byte(sampleEmptyCommand), s) | ||
|
||
assert.Nil(t, err) | ||
assert.Nil(t, s.Command) | ||
|
||
bytes, err := yaml.Marshal(s) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "{}", strings.TrimSpace(string(bytes))) | ||
|
||
s2 := &StructCommand{} | ||
err = yaml.Unmarshal(bytes, s2) | ||
|
||
assert.Nil(t, err) | ||
assert.Nil(t, s2.Command) | ||
} |
Oops, something went wrong.