Skip to content

Commit

Permalink
add buildrun log unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gabemontero committed Jul 26, 2021
1 parent 8af5ffb commit c442fe7
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pkg/shp/cmd/buildrun/logs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package buildrun

import (
"strings"
"testing"

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/cli/pkg/shp/params"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes/fake"

"github.com/spf13/cobra"
)

func TestStreamBuildLogs(t *testing.T) {
name := "test-obj"
pod := &corev1.Pod{}
pod.Name = name
pod.Namespace = metav1.NamespaceDefault
pod.Labels = map[string]string{
v1alpha1.LabelBuildRun: name,
}
pod.Spec.Containers = []corev1.Container{
{
Name: name,
},
}

cmd := LogsCommand{cmd: &cobra.Command{}}
cmd.name = name
// set up context
cmd.Cmd().ExecuteC()

clientset := fake.NewSimpleClientset(pod)
ioStreams, _, out, _ := genericclioptions.NewTestIOStreams()
param := params.NewParamsForTest(clientset, nil, nil, metav1.NamespaceDefault)
err := cmd.Run(param, &ioStreams)
if err != nil {
t.Fatalf("%s", err.Error())
}
if !strings.Contains(out.String(), "fake logs") {
t.Fatalf("unexpected output: %s", out.String())
}

t.Logf("%s", out.String())

}

0 comments on commit c442fe7

Please sign in to comment.