-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve integration tests and no more use wiremock for unit tests
- Loading branch information
Raphaël Benitte
committed
Jul 12, 2018
1 parent
b84bf94
commit 43579c8
Showing
97 changed files
with
5,697 additions
and
511 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/fatih/color" | ||
"github.com/plouc/go-gitlab-client/gitlab" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
lsCmd.AddCommand(lsSshKeysCmd) | ||
} | ||
|
||
func fetchSshKeys() { | ||
color.Yellow("Fetching current user ssh keys…") | ||
|
||
o := &gitlab.PaginationOptions{} | ||
o.Page = page | ||
o.PerPage = perPage | ||
|
||
loader.Start() | ||
keys, meta, err := client.CurrentUserSshKeys(o) | ||
loader.Stop() | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
|
||
if len(keys) == 0 { | ||
color.Red("No ssh key found") | ||
} else { | ||
sshKeysOutput(keys) | ||
} | ||
|
||
metaOutput(meta, true) | ||
|
||
handlePaginatedResult(meta, fetchSshKeys) | ||
} | ||
|
||
var lsSshKeysCmd = &cobra.Command{ | ||
Use: "ssh-keys", | ||
Aliases: []string{"sk"}, | ||
Short: "List current user ssh keys", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fetchSshKeys() | ||
}, | ||
} |
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,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/fatih/color" | ||
"github.com/plouc/go-gitlab-client/gitlab" | ||
"github.com/spf13/cobra" | ||
"strconv" | ||
) | ||
|
||
func init() { | ||
lsCmd.AddCommand(lsUserSshKeysCmd) | ||
} | ||
|
||
func fetchUserSshKeys(userId int) { | ||
color.Yellow("Fetching user %d ssh keys…", userId) | ||
|
||
o := &gitlab.PaginationOptions{} | ||
o.Page = page | ||
o.PerPage = perPage | ||
|
||
loader.Start() | ||
keys, meta, err := client.CurrentUserSshKeys(o) | ||
loader.Stop() | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
return | ||
} | ||
|
||
if len(keys) == 0 { | ||
color.Red("No ssh key found for user: %d", userId) | ||
} else { | ||
sshKeysOutput(keys) | ||
} | ||
|
||
metaOutput(meta, true) | ||
|
||
handlePaginatedResult(meta, func() { | ||
fetchUserSshKeys(userId) | ||
}) | ||
} | ||
|
||
var lsUserSshKeysCmd = &cobra.Command{ | ||
Use: resourceCmd("user-ssh-keys", "user"), | ||
Aliases: []string{"usk"}, | ||
Short: "List specific user ssh keys", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ids, err := config.aliasIdsOrArgs(currentAlias, "user", args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userId, err := strconv.Atoi(ids["user_id"]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fetchUserSshKeys(userId) | ||
|
||
return nil | ||
}, | ||
} |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
"github.com/plouc/go-gitlab-client/gitlab" | ||
) | ||
|
||
func sshKeysOutput(keys []*gitlab.SshKey) { | ||
if outputFormat == "json" { | ||
jsonOutput(keys) | ||
} else if outputFormat == "yaml" { | ||
yamlOutput(keys) | ||
} else { | ||
fmt.Fprintln(output, "") | ||
table := tablewriter.NewWriter(output) | ||
table.SetHeader([]string{ | ||
"Id", | ||
"Title", | ||
"Key", | ||
"Created at", | ||
}) | ||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) | ||
for _, key := range keys { | ||
table.Append([]string{ | ||
fmt.Sprintf("%d", key.Id), | ||
key.Title, | ||
key.Key[:16] + "…", | ||
key.CreatedAtRaw, | ||
}) | ||
} | ||
table.Render() | ||
fmt.Fprintln(output, "") | ||
} | ||
} |
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,36 @@ | ||
package gitlab | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProjectBadges(t *testing.T) { | ||
ts, gitlab := mockServerFromMapping(t, "badges/project_1_badges.json") | ||
defer ts.Close() | ||
|
||
badges, meta, err := gitlab.ProjectBadges("1", nil) | ||
|
||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 5, len(badges)) | ||
|
||
assert.IsType(t, new(ResponseMeta), meta) | ||
assert.Equal(t, 1, meta.Page) | ||
assert.Equal(t, 10, meta.PerPage) | ||
} | ||
|
||
func TestProjectBadge(t *testing.T) { | ||
ts, gitlab := mockServerFromMapping(t, "badges/project_1_badge_1.json") | ||
defer ts.Close() | ||
|
||
badge, meta, err := gitlab.ProjectBadge("1", 1) | ||
|
||
assert.NoError(t, err) | ||
|
||
assert.IsType(t, new(Badge), badge) | ||
assert.Equal(t, 1, badge.Id) | ||
|
||
assert.IsType(t, new(ResponseMeta), meta) | ||
} |
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,22 @@ | ||
package gitlab | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProjectBranches(t *testing.T) { | ||
ts, gitlab := mockServerFromMapping(t, "branches/project_1_branches.json") | ||
defer ts.Close() | ||
|
||
branches, meta, err := gitlab.ProtectedBranches("1", nil) | ||
|
||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 10, len(branches)) | ||
|
||
assert.IsType(t, new(ResponseMeta), meta) | ||
assert.Equal(t, 1, meta.Page) | ||
assert.Equal(t, 10, meta.PerPage) | ||
} |
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.