github.com/actions-on-google/gactions@v3.2.0+incompatible/cmd/gactions/cli/push/push_test.go (about) 1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package push 16 17 import ( 18 "bytes" 19 "context" 20 "fmt" 21 "testing" 22 23 "github.com/actions-on-google/gactions/project" 24 "github.com/actions-on-google/gactions/project/studio" 25 "github.com/spf13/cobra" 26 ) 27 28 func TestCmdExecute(cmd *cobra.Command, args []string) (string, error) { 29 output := new(bytes.Buffer) 30 cmd.SetOutput(output) 31 cmd.SetArgs(args) 32 err := cmd.Execute() 33 return output.String(), err 34 } 35 36 func execute(args ...string) (string, error) { 37 cmd := &cobra.Command{} 38 project := studio.New([]byte{}, ".") 39 AddCommand(context.Background(), cmd, project) 40 return TestCmdExecute(cmd, args) 41 } 42 43 func TestPush(t *testing.T) { 44 // TODO: Need to setup a settings.yaml file so command can read it to get projectID. 45 t.Skip() 46 originalDoPush := doPush 47 defer func() { 48 doPush = originalDoPush 49 }() 50 doPush = func(ctx context.Context, cmd *cobra.Command, args []string, proj project.Project) error { 51 if proj == nil { 52 return fmt.Errorf("proj is %v, want not nil", proj) 53 } 54 return nil 55 } 56 if _, err := execute("push"); err != nil { 57 t.Errorf("push failed and returned %v, want %v", err.Error(), nil) 58 } 59 }