-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user as docker backend_option (#4526)
- Loading branch information
Showing
9 changed files
with
221 additions
and
93 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,21 @@ | ||
package docker | ||
|
||
import ( | ||
"github.com/mitchellh/mapstructure" | ||
|
||
backend "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types" | ||
) | ||
|
||
// BackendOptions defines all the advanced options for the docker backend. | ||
type BackendOptions struct { | ||
User string `mapstructure:"user"` | ||
} | ||
|
||
func parseBackendOptions(step *backend.Step) (BackendOptions, error) { | ||
var result BackendOptions | ||
if step == nil || step.BackendOptions == nil { | ||
return result, nil | ||
} | ||
err := mapstructure.Decode(step.BackendOptions[EngineName], &result) | ||
return result, err | ||
} |
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,56 @@ | ||
package docker | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
backend "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types" | ||
) | ||
|
||
func Test_parseBackendOptions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
step *backend.Step | ||
want BackendOptions | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "nil options", | ||
step: &backend.Step{BackendOptions: nil}, | ||
want: BackendOptions{}, | ||
}, | ||
{ | ||
name: "empty options", | ||
step: &backend.Step{BackendOptions: map[string]any{}}, | ||
want: BackendOptions{}, | ||
}, | ||
{ | ||
name: "with user option", | ||
step: &backend.Step{BackendOptions: map[string]any{ | ||
"docker": map[string]any{ | ||
"user": "1000:1000", | ||
}, | ||
}}, | ||
want: BackendOptions{User: "1000:1000"}, | ||
}, | ||
{ | ||
name: "invalid backend options", | ||
step: &backend.Step{BackendOptions: map[string]any{"docker": "invalid"}}, | ||
want: BackendOptions{}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := parseBackendOptions(tt.step) | ||
if tt.wantErr { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.