Skip to content

Commit

Permalink
add appidentifier property. update client command to take appIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
maleck13 committed Jan 25, 2018
1 parent 92dda06 commit 0b24745
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 25 deletions.
7 changes: 4 additions & 3 deletions pkg/apis/mobile/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ type MobileClientList struct {
}

type MobileClientSpec struct {
Name string
ApiKey string
ClientType string
Name string
ApiKey string
ClientType string
AppIdentifier string
}

// +genclient
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/mobile/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ type MobileClientList struct {
}

type MobileClientSpec struct {
Name string `json:"name"`
ApiKey string `json:"apiKey"`
ClientType string `json:"clientType"`
Name string `json:"name"`
ApiKey string `json:"apiKey"`
ClientType string `json:"clientType"`
AppIdentifier string `json:"appIdentifier"`
}

// +genclient
Expand Down
27 changes: 14 additions & 13 deletions pkg/cmd/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ oc plugin mobile get clients`,
mClients := mobileClientList.(*v1alpha1.MobileClientList)
var data [][]string
for _, mClient := range mClients.Items {
data = append(data, []string{mClient.Name, mClient.Spec.Name, mClient.Spec.ClientType})
data = append(data, []string{mClient.Name, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.AppIdentifier})
}
table := tablewriter.NewWriter(out)
table.AppendBulk(data)
table.SetHeader([]string{"ID", "Name", "ClientType"})
table.SetHeader([]string{"ID", "Name", "ClientType", "AppIdentifier"})
table.Render()
return nil
})
Expand Down Expand Up @@ -97,10 +97,10 @@ oc plugin mobile get client <clientID>`,
cc.Out.AddRenderer(command.Name(), "table", func(out io.Writer, mobileClient interface{}) error {
mClient := mobileClient.(*v1alpha1.MobileClient)
var data [][]string
data = append(data, []string{mClient.Name, mClient.Namespace, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.ApiKey})
data = append(data, []string{mClient.Name, mClient.Namespace, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.ApiKey, mClient.Spec.AppIdentifier})
table := tablewriter.NewWriter(out)
table.AppendBulk(data)
table.SetHeader([]string{"ID", "Namespace", "Name", "ClientType", "ApiKey"})
table.SetHeader([]string{"ID", "Namespace", "Name", "ClientType", "ApiKey", "AppIdentifier"})
table.Render()
return nil
})
Expand All @@ -110,23 +110,24 @@ oc plugin mobile get client <clientID>`,
// CreateClientCmd builds the create mobileclient command
func (cc *ClientCmd) CreateClientCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "client <name> <clientType iOS|cordova|android>",
Use: "client <name> <clientType iOS|cordova|android> <appIdentifier bundleID|packageName >",
Short: "create a mobile client representation in your namespace",
Long: `Sets up the representation of a mobile application of the specified type in your namespace.
This is used to provide a mobile client context for various actions such as creating, starting or stopping mobile client builds.
The available client types are android, cordova and iOS.
When used standalone, a namespace must be specified by providing the --namespace flag.`,
Example: ` mobile create client <name> <clientType> --namespace=myproject
kubectl plugin mobile create client <name> <clientType>
oc plugin mobile create client <name> <clientType>`,
Example: ` mobile create client <name> <clientType> <appIdentifier> --namespace=myproject
kubectl plugin mobile create client <name> <clientType> <appIdentifier>
oc plugin mobile create client <name> <clientType> <appIdentifier>`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
return errors.New("expected a name and a clientType")
if len(args) != 3 {
return errors.New("expected a name a clientType and a appIdentifier")
}
name := args[0]
clientType := args[1]
appIdentifier := args[2]
appKey := uuid.NewV4().String()

namespace, err := currentNamespace(cmd.Flags())
Expand All @@ -141,7 +142,7 @@ When used standalone, a namespace must be specified by providing the --namespace
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{},
},
Spec: v1alpha1.MobileClientSpec{Name: name, ApiKey: appKey, ClientType: clientType},
Spec: v1alpha1.MobileClientSpec{Name: name, ApiKey: appKey, ClientType: clientType, AppIdentifier: appIdentifier},
}
switch app.Spec.ClientType {
case "android":
Expand Down Expand Up @@ -173,10 +174,10 @@ When used standalone, a namespace must be specified by providing the --namespace
cc.Out.AddRenderer("create"+cmd.Name(), "table", func(writer io.Writer, mobileClient interface{}) error {
mClient := mobileClient.(*v1alpha1.MobileClient)
var data [][]string
data = append(data, []string{mClient.Name, mClient.Spec.Name, mClient.Spec.ClientType})
data = append(data, []string{mClient.Name, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.AppIdentifier})
table := tablewriter.NewWriter(writer)
table.AppendBulk(data)
table.SetHeader([]string{"ID", "Name", "ClientType"})
table.SetHeader([]string{"ID", "Name", "ClientType", "AppIdentifier"})
table.Render()
return nil
})
Expand Down
35 changes: 29 additions & 6 deletions pkg/cmd/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestCreateClient(t *testing.T) {
}{
{
Name: "test create cordova mobile client succeeds without error",
Args: []string{"test", "cordova"},
Args: []string{"test", "cordova", "my.app.org"},
MobileClient: func() mc.Interface {
mc := &mcFake.Clientset{}
mc.AddReactor("create", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
Expand All @@ -300,6 +300,9 @@ func TestCreateClient(t *testing.T) {
if c.Spec.ClientType != "cordova" {
t.Fatal("expected the clientType to be cordova but got ", c.Spec.ClientType)
}
if c.Spec.AppIdentifier != "my.app.org" {
t.Fatal("expected an appIdentifier to be set as my.app.org but was ", c.Spec.AppIdentifier)
}
if c.Spec.Name != "test" {
t.Fatal("expected the client name to be test but got ", c.Spec.Name)
}
Expand All @@ -317,7 +320,7 @@ func TestCreateClient(t *testing.T) {
},
{
Name: "test create android mobile client succeeds without error",
Args: []string{"test", "android"},
Args: []string{"test", "android", "my.app.org"},
MobileClient: func() mc.Interface {
mc := &mcFake.Clientset{}
mc.AddReactor("create", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
Expand All @@ -337,6 +340,9 @@ func TestCreateClient(t *testing.T) {
if c.Spec.Name != "test" {
t.Fatal("expected the client name to be test but got ", c.Spec.Name)
}
if c.Spec.AppIdentifier != "my.app.org" {
t.Fatal("expected an appIdentifier to be set as my.app.org but was ", c.Spec.AppIdentifier)
}
if c.Spec.ApiKey == "" {
t.Fatal("expected an apiKey to be generated but it was empty")
}
Expand All @@ -351,7 +357,7 @@ func TestCreateClient(t *testing.T) {
},
{
Name: "test create iOS mobile client succeeds without error",
Args: []string{"test", "iOS"},
Args: []string{"test", "iOS", "my.app.org"},
MobileClient: func() mc.Interface {
mc := &mcFake.Clientset{}
mc.AddReactor("create", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
Expand All @@ -365,6 +371,9 @@ func TestCreateClient(t *testing.T) {
if nil == c {
t.Fatal("expected a mobile client but got nil")
}
if c.Spec.AppIdentifier != "my.app.org" {
t.Fatal("expected an appIdentifier to be set as my.app.org but was ", c.Spec.AppIdentifier)
}
if c.Spec.ClientType != "iOS" {
t.Fatal("expected the clientType to be iOS but got ", c.Spec.ClientType)
}
Expand All @@ -385,7 +394,7 @@ func TestCreateClient(t *testing.T) {
},
{
Name: "test create mobile client fails with unknown client type",
Args: []string{"test", "firefox"},
Args: []string{"test", "firefox", "my.app.org"},
ExpectError: true,
ErrorPattern: "^Failed validation while creating new mobile client: .*",
MobileClient: func() mc.Interface {
Expand All @@ -401,7 +410,7 @@ func TestCreateClient(t *testing.T) {
Name: "test create mobile client fails when missing required arguments",
Args: []string{"test"},
ExpectError: true,
ErrorPattern: "^expected a name and a clientType",
ErrorPattern: "^expected a name a clientType and a appIdentifier",
MobileClient: func() mc.Interface {
mc := &mcFake.Clientset{}
mc.AddReactor("create", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
Expand All @@ -413,7 +422,7 @@ func TestCreateClient(t *testing.T) {
},
{
Name: "test create mobile client fails with clear error message",
Args: []string{"test", "cordova"},
Args: []string{"test", "cordova", "my.app.org"},
ExpectError: true,
ErrorPattern: "^failed to create mobile client: something went wrong",
MobileClient: func() mc.Interface {
Expand All @@ -425,6 +434,20 @@ func TestCreateClient(t *testing.T) {
},
Flags: []string{"--namespace=myproject", "-o=json"},
},
{
Name: "test create mobile client fails when there is no appIdentifier",
Args: []string{"test", "android", ""},
ExpectError: true,
ErrorPattern: "^Failed validation while creating new mobile client: .*",
MobileClient: func() mc.Interface {
mc := &mcFake.Clientset{}
mc.AddReactor("create", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, errors.New("should not have been called")
})
return mc
},
Flags: []string{"--namespace=myproject", "-o=json"},
},
}

for _, tc := range cases {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/input/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ func ValidateMobileClient(client *v1alpha1.MobileClient) error {
if !ValidClients.Contains(client.Spec.ClientType) {
return errors.New("invalid clientType " + client.Spec.ClientType + " valid clientTypes are " + strings.Join(ValidClients, ","))
}
if client.Spec.AppIdentifier == "" {
return errors.New("expected an appIdentifier to be passed. It should not be empty. This should be the same as your bundleID or package name")
}
return nil
}

Expand Down

0 comments on commit 0b24745

Please sign in to comment.