github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/syz-manager/hub_test.go (about)

     1  // Copyright 2020 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  )
    10  
    11  func TestMatchDomains(t *testing.T) {
    12  	type Test struct {
    13  		self      string
    14  		input     string
    15  		minimized bool
    16  		smashed   bool
    17  	}
    18  	tests := []Test{
    19  		{"", "", true, true},
    20  		{"linux", "", true, true},
    21  		{"linux/", "", true, true},
    22  		{"linux/upstream/kasan", "", true, true},
    23  		{"", "linux", true, true},
    24  		{"", "linux/", true, true},
    25  		{"linux", "linux/", false, false},
    26  		{"linux/", "linux/", false, false},
    27  		{"linux", "linuz", true, true},
    28  		{"linux/upstream/kasan", "linuz", true, true},
    29  		{"linux/upstream", "linux/upstream", false, false},
    30  		{"linux/upstream", "linux/upstreax", true, true},
    31  		{"linux/upstream/", "linux/upstream", false, false},
    32  		{"linux/upstream", "linux/upstreax/", true, true},
    33  		{"linux/upstream", "linux/upstream/kasan", false, true},
    34  		{"linux/upstream/kasan", "linux/upstream", false, true},
    35  		{"linux/upstream/kasan", "linux/upstream/xasan", false, true},
    36  		{"linux/upstream/kasan", "linux/upstream/kasan", false, false},
    37  		{"linux/upstreax/kasan", "linux/upstream/kasan", true, true},
    38  		{"linux/upstreax/kasan", "linux/upstream/xasan", true, true},
    39  		{"linux/upstream/kasan", "linuz/upstream/xasan", true, true},
    40  	}
    41  	for i, test := range tests {
    42  		t.Run(fmt.Sprint(i), func(t *testing.T) {
    43  			minimized, smashed := matchDomains(test.self, test.input)
    44  			if minimized != test.minimized || smashed != test.smashed {
    45  				t.Fatalf("(%q, %q) = %v/%v, want %v/%v",
    46  					test.self, test.input, minimized, smashed, test.minimized, test.smashed)
    47  			}
    48  		})
    49  	}
    50  }