github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/api/checks/update_medium_test.go (about)

     1  //go:build medium
     2  // +build medium
     3  
     4  // Copyright 2018 The WPT Dashboard Project. All rights reserved.
     5  // Use of this source code is governed by a BSD-style license that can be
     6  // found in the LICENSE file.
     7  package checks
     8  
     9  import (
    10  	"strconv"
    11  	"strings"
    12  	"testing"
    13  	"time"
    14  
    15  	"github.com/stretchr/testify/assert"
    16  	"github.com/web-platform-tests/wpt.fyi/shared"
    17  	"github.com/web-platform-tests/wpt.fyi/shared/sharedtest"
    18  )
    19  
    20  func TestLoadRunsToCompare_master(t *testing.T) {
    21  	ctx, done, err := sharedtest.NewAEContext(true)
    22  	assert.Nil(t, err)
    23  	defer done()
    24  
    25  	testRun := shared.TestRun{
    26  		ProductAtRevision: shared.ProductAtRevision{
    27  			Product: shared.Product{
    28  				BrowserName: "chrome",
    29  			},
    30  		},
    31  		Labels: []string{"master"},
    32  	}
    33  	yesterday := time.Now().AddDate(0, 0, -1)
    34  	store := shared.NewAppEngineDatastore(ctx, false)
    35  	for i := 0; i < 2; i++ {
    36  		testRun.FullRevisionHash = strings.Repeat(strconv.Itoa(i), 40)
    37  		testRun.Revision = testRun.FullRevisionHash[:10]
    38  		testRun.TimeStart = yesterday.Add(time.Duration(i) * time.Hour)
    39  		key := store.NewIncompleteKey("TestRun")
    40  		key, _ = store.Put(key, &testRun)
    41  	}
    42  
    43  	chrome, _ := shared.ParseProductSpec("chrome")
    44  	filter := shared.TestRunFilter{
    45  		SHAs:     shared.SHAs{"1111111111"},
    46  		Products: shared.ProductSpecs{chrome},
    47  	}
    48  	headRun, baseRun, err := loadRunsToCompare(ctx, filter)
    49  
    50  	assert.Nil(t, err)
    51  	assert.NotNil(t, headRun)
    52  	assert.NotNil(t, baseRun)
    53  	assert.Equal(t, "0000000000", baseRun.Revision)
    54  	assert.Equal(t, "1111111111", headRun.Revision)
    55  }
    56  
    57  func TestLoadRunsToCompare_pr_base_first(t *testing.T) {
    58  	ctx, done, err := sharedtest.NewAEContext(true)
    59  	assert.Nil(t, err)
    60  	defer done()
    61  
    62  	labelsForRuns := [][]string{{"pr_base"}, {"pr_head"}}
    63  	yesterday := time.Now().AddDate(0, 0, -1)
    64  	store := shared.NewAppEngineDatastore(ctx, false)
    65  	for i := 0; i < 2; i++ {
    66  		testRun := shared.TestRun{
    67  			ProductAtRevision: shared.ProductAtRevision{
    68  				Product: shared.Product{
    69  					BrowserName: "chrome",
    70  				},
    71  				Revision:         "1234567890",
    72  				FullRevisionHash: "1234567890123456789012345678901234567890",
    73  			},
    74  			TimeStart: yesterday.Add(time.Duration(i) * time.Hour),
    75  			Labels:    labelsForRuns[i],
    76  		}
    77  		key := store.NewIncompleteKey("TestRun")
    78  		key, _ = store.Put(key, &testRun)
    79  	}
    80  
    81  	chrome, _ := shared.ParseProductSpec("chrome")
    82  	filter := shared.TestRunFilter{
    83  		SHAs:     shared.SHAs{"1234567890"},
    84  		Products: shared.ProductSpecs{chrome},
    85  	}
    86  	headRun, baseRun, err := loadRunsToCompare(ctx, filter)
    87  
    88  	assert.Nil(t, err)
    89  	assert.NotNil(t, headRun)
    90  	assert.NotNil(t, baseRun)
    91  	assert.Equal(t, []string{"pr_base"}, baseRun.Labels)
    92  	assert.Equal(t, []string{"pr_head"}, headRun.Labels)
    93  }
    94  
    95  func TestLoadRunsToCompare_pr_head_first(t *testing.T) {
    96  	ctx, done, err := sharedtest.NewAEContext(true)
    97  	assert.Nil(t, err)
    98  	defer done()
    99  
   100  	labelsForRuns := [][]string{{"pr_head"}, {"pr_base"}}
   101  	yesterday := time.Now().AddDate(0, 0, -1)
   102  	store := shared.NewAppEngineDatastore(ctx, false)
   103  	for i := 0; i < 2; i++ {
   104  		testRun := shared.TestRun{
   105  			ProductAtRevision: shared.ProductAtRevision{
   106  				Product: shared.Product{
   107  					BrowserName: "chrome",
   108  				},
   109  				Revision:         "1234567890",
   110  				FullRevisionHash: "1234567890123456789012345678901234567890",
   111  			},
   112  			TimeStart: yesterday.Add(time.Duration(i) * time.Hour),
   113  			Labels:    labelsForRuns[i],
   114  		}
   115  		key := store.NewIncompleteKey("TestRun")
   116  		key, _ = store.Put(key, &testRun)
   117  	}
   118  
   119  	chrome, _ := shared.ParseProductSpec("chrome")
   120  	filter := shared.TestRunFilter{
   121  		SHAs:     shared.SHAs{"1234567890"},
   122  		Products: shared.ProductSpecs{chrome},
   123  	}
   124  	headRun, baseRun, err := loadRunsToCompare(ctx, filter)
   125  
   126  	assert.Nil(t, err)
   127  	assert.NotNil(t, headRun)
   128  	assert.NotNil(t, baseRun)
   129  	assert.Equal(t, []string{"pr_base"}, baseRun.Labels)
   130  	assert.Equal(t, []string{"pr_head"}, headRun.Labels)
   131  }