MCPcopy Create free account
hub / github.com/bufbuild/buf / TestModuleCycleError

Function TestModuleCycleError

private/bufpkg/bufmodule/bufmodule_test.go:361–445  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

359}
360
361func TestModuleCycleError(t *testing.T) {
362 t.Parallel()
363
364 moduleSet, err := bufmoduletesting.NewOmniProvider(
365 bufmoduletesting.ModuleData{
366 Name: "buf.build/foo/a",
367 PathToData: map[string][]byte{
368 "a.proto": []byte(
369 `syntax = proto3; package a; import "b.proto";`,
370 ),
371 "a1.proto": []byte(
372 `syntax = proto3; package a;`,
373 ),
374 },
375 },
376 bufmoduletesting.ModuleData{
377 Name: "buf.build/foo/b",
378 PathToData: map[string][]byte{
379 "b.proto": []byte(
380 `syntax = proto3; package b; import "c.proto";`,
381 ),
382 },
383 },
384 bufmoduletesting.ModuleData{
385 Name: "buf.build/foo/c",
386 PathToData: map[string][]byte{
387 "c.proto": []byte(
388 `syntax = proto3; package b; import "a1.proto";`,
389 ),
390 },
391 },
392 )
393 require.NoError(t, err)
394
395 moduleA := moduleSet.GetModuleForOpaqueID("buf.build/foo/a")
396 require.NotNil(t, moduleA)
397 _, err = moduleA.ModuleDeps()
398 require.Error(t, err)
399 moduleCycleError := &bufmodule.ModuleCycleError{}
400 require.True(t, errors.As(err, &moduleCycleError), err.Error())
401 require.Equal(
402 t,
403 []string{
404 "buf.build/foo/a",
405 "buf.build/foo/b",
406 "buf.build/foo/c",
407 "buf.build/foo/a",
408 },
409 moduleCycleError.Descriptions,
410 )
411
412 moduleB := moduleSet.GetModuleForOpaqueID("buf.build/foo/b")
413 require.NotNil(t, moduleB)
414 _, err = moduleB.ModuleDeps()
415 require.Error(t, err)
416 moduleCycleError = &bufmodule.ModuleCycleError{}
417 require.True(t, errors.As(err, &moduleCycleError), err.Error())
418 require.Equal(

Callers

nothing calls this directly

Calls 4

NewOmniProviderFunction · 0.92
GetModuleForOpaqueIDMethod · 0.65
ModuleDepsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…