...

Source file src/edge-infra.dev/hack/build/ci/leaf/pkg/go/parse_deps_test.go

Documentation: edge-infra.dev/hack/build/ci/leaf/pkg/go

     1  package golang_test
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  	"testing"
     7  
     8  	golang "edge-infra.dev/hack/build/ci/leaf/pkg/go"
     9  )
    10  
    11  func TestDiffParsing(t *testing.T) {
    12  	tcs := []struct {
    13  		Description string
    14  		DiffPath    string
    15  		Targets     map[string]struct{}
    16  	}{
    17  		{
    18  			Description: "Simple deps.bzl diff",
    19  			DiffPath:    "testdata/deps-bzl-diff",
    20  			Targets: map[string]struct{}{
    21  				"@com_github_sourcegraph_go_diff//...":   {},
    22  				"@in_gopkg_yaml_v3//...":                 {},
    23  				"@com_github_pkg_errors//...":            {},
    24  				"@com_github_mattn_go_isatty//...":       {},
    25  				"@com_github_cpuguy83_go_md2man_v2//...": {},
    26  			},
    27  		},
    28  		{
    29  			Description: "deps.bzl diff with build_file_name",
    30  			DiffPath:    "testdata/deps-bzl-diff-multiple-name-strings",
    31  			Targets: map[string]struct{}{
    32  				"@com_github_envoyproxy_go_control_plane//...": {},
    33  				"@com_github_golang_groupcache//...":           {},
    34  				"@com_github_golang_mock//...":                 {},
    35  				"@com_github_golang_snappy//...":               {},
    36  				"@com_github_google_martian_v3//...":           {},
    37  				"@com_github_google_pprof//...":                {},
    38  				"@com_github_googleapis_gax_go_v2//...":        {},
    39  				"@com_github_grpc_ecosystem_grpc_gateway//...": {},
    40  				"@com_github_rogpeppe_fastuuid//...":           {},
    41  				"@com_google_cloud_go//...":                    {},
    42  				"@com_google_cloud_go_storage//...":            {},
    43  				"@org_golang_google_api//...":                  {},
    44  				"@org_golang_google_protobuf//...":             {},
    45  				"@org_golang_x_lint//...":                      {},
    46  				"@org_golang_x_oauth2//...":                    {},
    47  				"@org_golang_x_sys//...":                       {},
    48  				"@org_golang_x_text//...":                      {},
    49  				"@org_golang_x_tools//...":                     {},
    50  			},
    51  		},
    52  		{
    53  			Description: "More complex deps.bzl diff",
    54  			DiffPath:    "testdata/deps-bzl-diff-huge",
    55  			Targets: map[string]struct{}{
    56  				"@com_github_beorn7_perks//...":                {},
    57  				"@com_github_coreos_bbolt//...":                {},
    58  				"@com_github_coreos_pkg//...":                  {},
    59  				"@com_github_elazarl_goproxy//...":             {},
    60  				"@com_github_fsnotify_fsnotify//...":           {},
    61  				"@com_github_go_logfmt_logfmt//...":            {},
    62  				"@com_github_gogo_protobuf//...":               {},
    63  				"@com_github_golang_groupcache//...":           {},
    64  				"@com_github_golang_protobuf//...":             {},
    65  				"@com_github_google_gofuzz//...":               {},
    66  				"@com_github_hashicorp_golang_lru//...":        {},
    67  				"@com_github_imdario_mergo//...":               {},
    68  				"@com_github_json_iterator_go//...":            {},
    69  				"@com_github_onsi_ginkgo//...":                 {},
    70  				"@com_github_onsi_gomega//...":                 {},
    71  				"@com_github_prometheus_client_model//...":     {},
    72  				"@com_github_prometheus_procfs//...":           {},
    73  				"@com_github_spf13_cobra//...":                 {},
    74  				"@com_github_spf13_viper//...":                 {},
    75  				"@com_github_tmc_grpc_websocket_proxy//...":    {},
    76  				"@in_gopkg_yaml_v2//...":                       {},
    77  				"@io_k8s_api//...":                             {},
    78  				"@io_k8s_apimachinery//...":                    {},
    79  				"@io_k8s_apiextensions_apiserver//...":         {},
    80  				"@io_k8s_apiserver//...":                       {},
    81  				"@io_k8s_client_go//...":                       {},
    82  				"@io_k8s_code_generator//...":                  {},
    83  				"@io_k8s_component_base//...":                  {},
    84  				"@io_k8s_gengo//...":                           {},
    85  				"@io_k8s_kube_openapi//...":                    {},
    86  				"@io_k8s_sigs_controller_runtime//...":         {},
    87  				"@io_k8s_sigs_controller_tools//...":           {},
    88  				"@io_k8s_sigs_yaml//...":                       {},
    89  				"@io_k8s_utils//...":                           {},
    90  				"@org_golang_google_genproto//...":             {},
    91  				"@org_golang_google_grpc//...":                 {},
    92  				"@org_golang_google_protobuf//...":             {},
    93  				"@org_golang_x_net//...":                       {},
    94  				"@org_golang_x_text//...":                      {},
    95  				"@org_golang_x_tools//...":                     {},
    96  				"@org_uber_go_atomic//...":                     {},
    97  				"@org_golang_x_mod//...":                       {},
    98  				"@com_github_envoyproxy_go_control_plane//...": {},
    99  				"@com_github_yuin_goldmark//...":               {},
   100  				"@com_github_cpuguy83_go_md2man_v2//...":       {},
   101  			},
   102  		},
   103  	}
   104  
   105  	for _, tc := range tcs {
   106  		diffBytes, err := os.ReadFile(tc.DiffPath)
   107  		if err != nil {
   108  			t.Error(err)
   109  		}
   110  		results := golang.Parse(strings.Split(string(diffBytes), "\n"))
   111  		t.Logf("Parsed modules: %s", results)
   112  		if len(results) != len(tc.Targets) {
   113  			t.Errorf("Parse: Expected %d results, got %v", len(tc.Targets), len(results))
   114  		}
   115  		for _, result := range results {
   116  			if _, ok := tc.Targets[result]; !ok {
   117  				t.Errorf("Parse: Expected to find %s in result", result)
   118  			}
   119  		}
   120  	}
   121  }
   122  

View as plain text