-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust the parameter priority of oss bridge
- Loading branch information
1 parent
f36184a
commit ca31463
Showing
5 changed files
with
113 additions
and
7 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 |
---|---|---|
|
@@ -2,6 +2,6 @@ package main | |
|
||
import "testing" | ||
|
||
func TestMain(t *testing.T) { | ||
func TestMain(m *testing.M) { | ||
Main([]string{}) | ||
} |
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 |
---|---|---|
@@ -1,9 +1,71 @@ | ||
package lib | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/aliyun/aliyun-cli/cli" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestCliBridge(t *testing.T) { | ||
NewCommandBridge(configCommand.command) | ||
} | ||
|
||
func TestParseAndGetEndpoint(t *testing.T) { | ||
type args struct { | ||
ctx *cli.Context | ||
args []string | ||
} | ||
w := new(bytes.Buffer) | ||
stderr := new(bytes.Buffer) | ||
context := cli.NewCommandContext(w, stderr) | ||
flag := cli.Flag{ | ||
Name: "endpoint", | ||
} | ||
flag.SetValue("oss-cn-hangzhou.aliyuncs.com") | ||
context.Flags().Add(&flag) | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "Valid endpoint from args", | ||
args: args{ | ||
ctx: new(cli.Context), | ||
args: []string{"--endpoint", "oss-cn-shenzhen.aliyuncs.com"}, | ||
}, | ||
want: "oss-cn-shenzhen.aliyuncs.com", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "Valid region from args", | ||
args: args{ | ||
ctx: new(cli.Context), | ||
args: []string{"--region", "cn-shenzhen"}, | ||
}, | ||
want: "oss-cn-shenzhen.aliyuncs.com", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "Fetch endpoint flag from context", | ||
args: args{ | ||
ctx: context, | ||
}, | ||
want: "oss-cn-hangzhou.aliyuncs.com", | ||
wantErr: assert.NoError, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParseAndGetEndpoint(tt.args.ctx, tt.args.args) | ||
if !tt.wantErr(t, err, fmt.Sprintf("ParseAndGetEndpoint(%v, %v)", tt.args.ctx, tt.args.args)) { | ||
return | ||
} | ||
assert.Equalf(t, tt.want, got, "ParseAndGetEndpoint(%v, %v)", tt.args.ctx, tt.args.args) | ||
}) | ||
} | ||
} |