github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/spyglass/podlogartifact_fetcher_test.go (about)

     1  /*
     2  Copyright 2018 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 spyglass
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  // Tests getting handles to objects associated with the current Prow job
    24  func TestFetchArtifacts_Prow(t *testing.T) {
    25  	goodFetcher := NewPodLogArtifactFetcher(&fakePodLogJAgent{})
    26  	maxSize := int64(500e6)
    27  	testCases := []struct {
    28  		name      string
    29  		job       string
    30  		buildID   string
    31  		expectErr bool
    32  	}{
    33  		{
    34  			name:    "Fetch build-log.txt from valid src",
    35  			job:     "BFG",
    36  			buildID: "435",
    37  		},
    38  		{
    39  			name:      "Fetch log from empty src",
    40  			job:       "",
    41  			buildID:   "",
    42  			expectErr: true,
    43  		},
    44  		{
    45  			name:      "Fetch log from incomplete src",
    46  			job:       "BFG",
    47  			buildID:   "",
    48  			expectErr: true,
    49  		},
    50  	}
    51  
    52  	for _, tc := range testCases {
    53  		artifact, err := goodFetcher.artifact(tc.job, tc.buildID, maxSize)
    54  		if err != nil && !tc.expectErr {
    55  			t.Errorf("%s: failed unexpectedly for artifact %s, err: %v", tc.name, artifact.JobPath(), err)
    56  		}
    57  		if err == nil && tc.expectErr {
    58  			t.Errorf("%s: expected error, got no error", tc.name)
    59  		}
    60  	}
    61  }