update
This commit is contained in:
23
cmd/auth/gettest_test.go
Normal file
23
cmd/auth/gettest_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"testing"
|
||||
|
||||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
func TestGetToken(t *testing.T) {
|
||||
|
||||
keyring.MockInit()
|
||||
user, _ := user.Current()
|
||||
err := keyring.Set("durpcli", user.Username, "password")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
token := gettoken()
|
||||
if token != "password" {
|
||||
t.Error("password was not expected string")
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,9 @@ var getTokenCmd = &cobra.Command{
|
||||
Short: "",
|
||||
Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
gettokn()
|
||||
token := gettoken()
|
||||
|
||||
fmt.Println(token)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -23,7 +25,7 @@ func init() {
|
||||
AuthCmd.AddCommand(getTokenCmd)
|
||||
}
|
||||
|
||||
func gettokn() {
|
||||
func gettoken() string {
|
||||
|
||||
service := "durpcli"
|
||||
user, _ := user.Current()
|
||||
@@ -33,5 +35,5 @@ func gettokn() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(token)
|
||||
return token
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"os/user"
|
||||
|
||||
"github.com/cli/oauth/device"
|
||||
"github.com/dreamsofcode-io/terminal-ui/spinner"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/zalando/go-keyring"
|
||||
@@ -21,7 +22,10 @@ var loginCmd = &cobra.Command{
|
||||
if clientID == "" {
|
||||
clientID = viper.GetViper().GetString("auth.clientID")
|
||||
}
|
||||
s := spinner.New(spinner.Config{})
|
||||
s.Start()
|
||||
login(clientID)
|
||||
s.Stop()
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user