github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/prow/cmd/deck/jobs_test.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "bytes" 21 "fmt" 22 "io" 23 "io/ioutil" 24 "testing" 25 26 "k8s.io/test-infra/prow/kube" 27 ) 28 29 type fkc []kube.ProwJob 30 31 func (f fkc) ListProwJobs(l map[string]string) ([]kube.ProwJob, error) { 32 return f, nil 33 } 34 35 type fpkc struct{} 36 37 func (f fpkc) GetLog(pod string) ([]byte, error) { 38 if pod == "wowowow" { 39 return []byte("wow"), nil 40 } 41 return nil, fmt.Errorf("pod not found: %s", pod) 42 } 43 44 func (f fpkc) GetLogStream(pod string, options map[string]string) (io.ReadCloser, error) { 45 if pod == "wowowow" { 46 return ioutil.NopCloser(bytes.NewBuffer([]byte("wow"))), nil 47 } 48 return nil, fmt.Errorf("pod not found: %s", pod) 49 } 50 51 func TestGetLog(t *testing.T) { 52 kc := fkc{ 53 kube.ProwJob{ 54 Spec: kube.ProwJobSpec{ 55 Agent: kube.KubernetesAgent, 56 Job: "job", 57 }, 58 Status: kube.ProwJobStatus{ 59 PodName: "wowowow", 60 BuildID: "123", 61 }, 62 }, 63 } 64 ja := &JobAgent{ 65 kc: kc, 66 pkc: &fpkc{}, 67 } 68 if err := ja.update(); err != nil { 69 t.Fatalf("Updating: %v", err) 70 } 71 if _, err := ja.GetJobLog("job", "123"); err != nil { 72 t.Fatalf("Failed to get log: %v", err) 73 } 74 }