github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/cmd/jenkins-operator/logs_test.go (about)

     1  /*
     2  Copyright 2022 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 "testing"
    20  
    21  func Test_getRealJenkinsLogPath(t *testing.T) {
    22  	tests := []struct {
    23  		name    string
    24  		path    string
    25  		want    string
    26  		wantErr bool
    27  	}{
    28  		{
    29  			name: "flatten job",
    30  			path: "/job/abc/1/consoleText",
    31  			want: "/job/abc/1/consoleText",
    32  		},
    33  		{
    34  			name: "nested job",
    35  			path: "job/folder-l1/foleer-L2/the-job/1/consoleText",
    36  			want: "job/folder-l1/job/foleer-L2/job/the-job/1/consoleText",
    37  		},
    38  		{
    39  			name: "nested job with lead slash",
    40  			path: "/job/folder-l1/foleer-L2/the-job/1/consoleText",
    41  			want: "/job/folder-l1/job/foleer-L2/job/the-job/1/consoleText",
    42  		},
    43  		{
    44  			name:    "invalid nested job",
    45  			path:    "job/.folder-l1/foleer-L2/the-job./1/consoleText",
    46  			wantErr: true,
    47  		},
    48  	}
    49  	for _, tt := range tests {
    50  		t.Run(tt.name, func(t *testing.T) {
    51  			got, err := getRealJenkinsLogPath(tt.path)
    52  			if (err != nil) != tt.wantErr {
    53  				t.Errorf("getRealJenkinsLogPath() error = %v, wantErr %v", err, tt.wantErr)
    54  				return
    55  			}
    56  			if got != tt.want {
    57  				t.Errorf("getRealJenkinsLogPath() = %v, want %v", got, tt.want)
    58  			}
    59  		})
    60  	}
    61  }