Skip to content

Commit

Permalink
Merge pull request #46 from dimitraz/cli-tests
Browse files Browse the repository at this point in the history
Update docs & test coverage
  • Loading branch information
maleck13 committed Jan 25, 2018
2 parents 51dc6d1 + 472d777 commit 9b0b4c6
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 66 deletions.
2 changes: 1 addition & 1 deletion cmd/mobile/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/base.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import "github.com/aerogear/mobile-cli/pkg/cmd/output"
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/clientBuild.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import "github.com/spf13/cobra"
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/clientBuild_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/clientConfig.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/clientConfig_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
Expand Down
41 changes: 30 additions & 11 deletions pkg/cmd/clients.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
Expand Down Expand Up @@ -31,10 +45,10 @@ func (cc *ClientCmd) ListClientsCmd() *cobra.Command {
command := &cobra.Command{
Use: "clients",
Short: "gets a list of mobile clients represented in the namespace",
Long: `Example: mobile get clients
mobile --namespace=myproject get clients
kubectl plugin mobile get clients
oc plugin mobile get clients`,
Long: `get clients allows you to get a list of mobile clients that are represented in your namespace.`,
Example: ` mobile get clients --namespace=myproject
kubectl plugin mobile get clients
oc plugin mobile get clients`,
RunE: func(cmd *cobra.Command, args []string) error {
ns, err := currentNamespace(cmd.Flags())
if err != nil {
Expand Down Expand Up @@ -71,9 +85,11 @@ func (cc *ClientCmd) GetClientCmd() *cobra.Command {
command := &cobra.Command{
Use: "client <clientID>",
Short: "gets a single mobile client in the namespace",
Long: `Example: mobile --namespace=myproject get client <clientID>
kubectl plugin mobile get client <clientID>
oc plugin mobile get client <clientID>`,
Long: `get client allows you to view client information for a specific mobile client in your namespace.
Run the "mobile get clients" command from this tool to get the client ID.`,
Example: ` mobile get client <clientID> --namespace=myproject
kubectl plugin mobile get client <clientID>
oc plugin mobile get client <clientID>`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("missing argument <clientID>")
Expand Down Expand Up @@ -112,7 +128,7 @@ func (cc *ClientCmd) CreateClientCmd() *cobra.Command {
cmd := &cobra.Command{
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.
Long: `create client 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.
Expand All @@ -121,6 +137,7 @@ When used standalone, a namespace must be specified by providing the --namespace
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) != 3 {
return errors.New("expected a name a clientType and a appIdentifier")
Expand Down Expand Up @@ -190,9 +207,11 @@ func (cc *ClientCmd) DeleteClientCmd() *cobra.Command {
command := &cobra.Command{
Use: "client <clientID>",
Short: "deletes a single mobile client in the namespace",
Long: `Example: mobile --namespace=myproject delete client <clientID>
kubectl plugin mobile delete client <clientID>
oc plugin mobile delete client <clientID>`,
Long: `delete client allows you to delete a single mobile client in your namespace.
Run the "mobile get clients" command from this tool to get the client ID.`,
Example: ` mobile delete client <clientID> --namespace=myproject
kubectl plugin mobile delete client <clientID>
oc plugin mobile delete client <clientID>`,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
var ns string
Expand Down
28 changes: 18 additions & 10 deletions pkg/cmd/clients_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd_test

import (
Expand All @@ -19,7 +33,7 @@ import (
kt "k8s.io/client-go/testing"
)

func TestListClients(t *testing.T) {
func TestMobileClientsCmd_TestListClients(t *testing.T) {
cases := []struct {
Name string
MobileClient func() mc.Interface
Expand Down Expand Up @@ -97,7 +111,7 @@ func TestListClients(t *testing.T) {
}
}

func TestGetClient(t *testing.T) {
func TestMobileClientsCmd_TestGetClient(t *testing.T) {
cases := []struct {
Name string
ClientName string
Expand Down Expand Up @@ -195,15 +209,14 @@ func TestGetClient(t *testing.T) {
}
}

func TestDeleteClient(t *testing.T) {
func TestMobileClientsCmd_TestDeleteClient(t *testing.T) {
cases := []struct {
Name string
ClientName string
MobileClient func() mc.Interface
ExpectError bool
ErrorPattern string
Flags []string
Validate func(t *testing.T, c *v1alpha1.MobileClient)
}{
{
Name: "test delete client succeeds with no errors",
Expand All @@ -220,7 +233,6 @@ func TestDeleteClient(t *testing.T) {
mc := &mcFake.Clientset{}
return mc
},

Flags: []string{"--namespace=myproject", "-o=json"},
ExpectError: true,
},
Expand All @@ -233,7 +245,6 @@ func TestDeleteClient(t *testing.T) {
})
return mc
},

Flags: []string{"--namespace=myproject", "-o=json"},
ExpectError: true,
},
Expand All @@ -254,7 +265,6 @@ func TestDeleteClient(t *testing.T) {
args = append(args, tc.ClientName)
}
err := deleteClient.RunE(deleteClient, args)

if tc.ExpectError && err == nil {
t.Fatal("expected an error but got none")
}
Expand All @@ -266,12 +276,11 @@ func TestDeleteClient(t *testing.T) {
t.Fatal("expected the error to match the pattern "+tc.ErrorPattern, err)
}
}

})
}
}

func TestCreateClient(t *testing.T) {
func TestMobileClientsCmd_TestCreateClient(t *testing.T) {
cases := []struct {
Name string
Args []string
Expand Down Expand Up @@ -479,7 +488,6 @@ func TestCreateClient(t *testing.T) {
}
tc.Validate(t, mobileClient)
}

})
}
}
14 changes: 14 additions & 0 deletions pkg/cmd/convert.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/create.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/delete.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/input/validate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package input

import (
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/integration.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/output/renderer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package output

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/serviceConfig.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 NAME HERE <EMAIL ADDRESS>
// Copyright Red Hat, Inc., and individual contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 9b0b4c6

Please sign in to comment.