k8s.io/test-infra/triage@v0.0.0-20240520184403-27c6b4c223d8/summarize/output_test.go (about)

     1  /*
     2  Copyright 2020 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 summarize
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestAnnotateOwners(t *testing.T) {
    24  	testCases := []struct {
    25  		name   string
    26  		test   string // The name of the test, containing an owner name
    27  		owner  string // What the owner should be
    28  		owners map[string][]string
    29  	}{
    30  		{"Prefixed", "[sig-node] Node reboots", "node", make(map[string][]string)},
    31  		{"None", "unknown test name", "testing", make(map[string][]string)},
    32  		{"Suffixed", "Suffixes too [sig-storage]", "storage", make(map[string][]string)},
    33  		{"Old-style prefixed", "Variable test with old-style prefixes", "node", map[string][]string{"node": {"Variable"}}},
    34  	}
    35  
    36  	for _, tc := range testCases {
    37  		t.Run(tc.name, func(t *testing.T) {
    38  			// Setup
    39  			now := int(1.5e9)
    40  			data := jsonOutput{
    41  				Clustered: []jsonCluster{
    42  					{
    43  						Tests: []test{
    44  							{
    45  								Name: tc.test,
    46  								Jobs: []job{
    47  									{
    48  										Name:         "somejob",
    49  										BuildNumbers: []string{"123", "125"},
    50  									},
    51  								},
    52  							},
    53  						},
    54  					},
    55  				},
    56  				Builds: columns{
    57  					JobPaths: map[string]string{"somejob": "/logs/somejob"},
    58  					Cols: columnarBuilds{
    59  						Started: []int{now},
    60  					},
    61  				},
    62  			}
    63  			builds := map[string]build{"/logs/somejob/123": {Started: now}}
    64  
    65  			// Run the test
    66  			err := annotateOwners(&data, builds, tc.owners)
    67  			if err != nil {
    68  				t.Errorf("annotateOwners(%#v, %#v, %#v) returned with an error: %s", data, builds, tc.owners, err)
    69  				return
    70  			}
    71  
    72  			if tc.owner != data.Clustered[0].Owner {
    73  				t.Errorf("annotateOwners(%#v, %#v, %#v) annotated an owner of %#v, wanted %#v", data, builds, tc.owners, data.Clustered[0].Owner, tc.owner)
    74  			}
    75  		})
    76  	}
    77  }
    78  
    79  func TestAnnotateOwnersEmptyParams(t *testing.T) {
    80  	err := annotateOwners(&jsonOutput{}, map[string]build{}, map[string][]string{})
    81  	if err != nil {
    82  		t.Errorf("annotateOwners(empty, empty, empty) returned with an error: %s", err)
    83  		return
    84  	}
    85  }