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

     1  //go:build small
     2  // +build small
     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  
     8  package azure
     9  
    10  import (
    11  	"encoding/json"
    12  	"testing"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  const artifactsJSON = `{
    18  	"count": 2,
    19  	"value": [{
    20  		"id": 1,
    21  		"name": "results-without-patch",
    22  		"resource": {
    23  			"type": "Container",
    24  			"data": "#/1714875/results-without-patch",
    25  			"properties": {
    26  				"localpath": "/Users/vsts/agent/2.142.1/work/1/a/wpt_report.json"
    27  			},
    28  			"url": "https://dev.azure.com/lukebjerring/92272aaf-ee0f-48f4-8c22-c1fa6648843c/_apis/build/builds/4/artifacts?artifactName=results-without-patch&api-version=5.0",
    29  			"downloadUrl": "https://dev.azure.com/lukebjerring/92272aaf-ee0f-48f4-8c22-c1fa6648843c/_apis/build/builds/4/artifacts?artifactName=results-without-patch&api-version=5.0&%24format=zip"
    30  		}
    31  	}, {
    32  		"id": 2,
    33  		"name": "results",
    34  		"resource": {
    35  			"type": "Container",
    36  			"data": "#/1714875/results",
    37  			"properties": {
    38  				"localpath": "/Users/vsts/agent/2.142.1/work/1/a/wpt_report.json"
    39  			},
    40  			"url": "https://dev.azure.com/lukebjerring/92272aaf-ee0f-48f4-8c22-c1fa6648843c/_apis/build/builds/4/artifacts?artifactName=results&api-version=5.0",
    41  			"downloadUrl": "https://dev.azure.com/lukebjerring/92272aaf-ee0f-48f4-8c22-c1fa6648843c/_apis/build/builds/4/artifacts?artifactName=results&api-version=5.0&%24format=zip"
    42  		}
    43  	}]
    44  }`
    45  
    46  func TestParses(t *testing.T) {
    47  	var artifacts BuildArtifacts
    48  	err := json.Unmarshal([]byte(artifactsJSON), &artifacts)
    49  	assert.Nil(t, err)
    50  	assert.Equal(t, int64(2), artifacts.Count)
    51  	assert.Len(t, artifacts.Value, 2)
    52  	for _, artifact := range artifacts.Value {
    53  		assert.NotEmpty(t, artifact.Resource.DownloadURL)
    54  	}
    55  }
    56  
    57  func TestArtifactRegexes(t *testing.T) {
    58  	// Names before https://github.com/web-platform-tests/wpt/pull/15110
    59  	assert.True(t, masterRegex.MatchString("results"))
    60  	assert.True(t, prHeadRegex.MatchString("affected-tests"))
    61  	assert.True(t, prBaseRegex.MatchString("affected-tests-without-changes"))
    62  
    63  	// Names after https://github.com/web-platform-tests/wpt/pull/15110
    64  	assert.True(t, masterRegex.MatchString("edge-results"))
    65  	assert.True(t, prHeadRegex.MatchString("safari-preview-affected-tests"))
    66  	assert.True(t, prBaseRegex.MatchString("safari-preview-affected-tests-without-changes"))
    67  
    68  	// Don't accept the other order
    69  	assert.False(t, masterRegex.MatchString("results-edge"))
    70  
    71  	// Don't accept any string ending with the right pattern
    72  	assert.False(t, masterRegex.MatchString("nodashresults"))
    73  
    74  	// Base and Head could be confused with substring matching
    75  	assert.False(t, prBaseRegex.MatchString("affected-tests"))
    76  	assert.False(t, prHeadRegex.MatchString("affected-tests-without-changes"))
    77  }
    78  
    79  func TestEpochBranchesRegex(t *testing.T) {
    80  	assert.True(t, epochBranchesRegex.MatchString("refs/heads/epochs/twelve_hourly"))
    81  	assert.True(t, epochBranchesRegex.MatchString("refs/heads/epochs/six_hourly"))
    82  	assert.True(t, epochBranchesRegex.MatchString("refs/heads/epochs/weekly"))
    83  	assert.True(t, epochBranchesRegex.MatchString("refs/heads/epochs/daily"))
    84  
    85  	assert.False(t, epochBranchesRegex.MatchString("refs/heads/weekly"))
    86  }