bufmoduletesting

package
v0.0.0-...-a078c60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TestDigest is a valid digest.
	//
	// This matches TestData.
	TestDigest = "b1-gLO3B_5ClhdU52w1gMOxk4GokvCoM1OqjarxMfjStGQ="
	// TestDigestB3WithConfiguration is a valid digest.
	//
	// This matches TestDataWithConfiguration.
	TestDigestB3WithConfiguration = "b3-b2gkRgE1WxTKpEfsK4ql8STGxqc6nRimCeMBGB5i2OU="
	// This matches TestDataWithConfigurationAndFallbackDocumentationPath.
	TestDigestB3WithConfigurationAndFallbackDocumentationPath = "b3-Zy8TSrRHq9GvkqVGz8bChvBEpAW3psNvXjzCHkxWzTE="
	// TestDigestWithDocumentation is a valid test digest.
	//
	// This matches TestDataWithDocumentation.
	TestDigestWithDocumentation = "b1-Vqi49Lw-sr3tTLQVwSJrRJnJSwV0yeg97ea957z02B0="
	// TestDigestB3WithLicense is a valid digest.
	//
	// This matches TestDataWithLicense.
	TestDigestB3WithLicense = "b3-j7iu4iVzYQUFr97mbq2PNAlM5UjEnjtwEas0q7g4DVM="
	// TestModuleReferenceFooBarV1String is a valid module reference string.
	TestModuleReferenceFooBarV1String = "buf.build/foob/bar:v1"
	// TestModuleReferenceFooBarV2String is a valid module reference string.
	TestModuleReferenceFooBarV2String = "buf.build/foob/bar:v2"
	// TestModuleReferenceFooBazV1String is a valid module reference string.
	TestModuleReferenceFooBazV1String = "buf.build/foob/baz:v1"
	// TestModuleReferenceFooBazV2String is a valid module reference string.
	TestModuleReferenceFooBazV2String = "buf.build/foob/baz:v2"
	// TestModuleDocumentation is a markdown module documentation file.
	TestModuleDocumentation = "# Module Documentation"
	// TestModuleDocumentationPath is the default path for module documentation file.
	TestModuleDocumentationPath = "buf.md"
	// TestModuleFallbackDocumentationPath is a fallback path for module documentation file.
	TestModuleFallbackDocumentationPath = "README.md"
	// TestModuleLicense is a txt module license file.
	TestModuleLicense = "Module License"
	// TestModuleConfiguration is a configuration file with an arbitrary module name,
	// and example lint and breaking configuration that covers every key. At least two
	// items are included in every key (where applicable) so that we validate whether
	// or not the digest is deterministic.
	TestModuleConfiguration = `` /* 837-byte string literal not displayed */

)

Variables

View Source
var (
	// TestData is the data that maps to TestDigest with TestModuleReferenceString.
	TestData = map[string][]byte{
		TestFile1Path: []byte(`syntax="proto3";`),
		TestFile2Path: []byte(`syntax="proto3";`),
	}
	//TestDataProto is the proto representation of TestData.
	TestDataProto = &modulev1alpha1.Module{
		Files: []*modulev1alpha1.ModuleFile{
			{
				Path:    TestFile1Path,
				Content: []byte(`syntax="proto3";`),
			},
			{
				Path:    TestFile2Path,
				Content: []byte(`syntax="proto3";`),
			},
		},
		BreakingConfig: &breakingv1.Config{Version: "v1beta1"},
		LintConfig:     &lintv1.Config{Version: "v1beta1"},
	}
	// TestDataWithDocumentation is the data that maps to TestDigestB3WithConfiguration.
	//
	// It includes a buf.md file.
	TestDataWithDocumentation = map[string][]byte{
		TestFile1Path:               []byte(`syntax="proto3";`),
		TestModuleDocumentationPath: []byte(TestModuleDocumentation),
	}
	// TestDataWithFallbackDocumentationPath is the data that maps to TestDigestWithDocumentation.
	//
	// It includes a README.md file.
	TestDataWithFallbackDocumentationPath = map[string][]byte{
		TestFile1Path:                       []byte(`syntax="proto3";`),
		TestModuleFallbackDocumentationPath: []byte(TestModuleDocumentation),
	}
	// TestDataWithDocumentationProto is the proto representation of TestDataWithDocumentation.
	TestDataWithDocumentationProto = &modulev1alpha1.Module{
		Files: []*modulev1alpha1.ModuleFile{
			{
				Path:    TestFile1Path,
				Content: []byte(`syntax="proto3";`),
			},
		},
		Documentation:     TestModuleDocumentation,
		DocumentationPath: TestModuleDocumentationPath,
		BreakingConfig:    &breakingv1.Config{Version: "v1beta1"},
		LintConfig:        &lintv1.Config{Version: "v1beta1"},
	}
	// TestDataWithConfiguration is the data that maps to TestDigestWithConfiguration.
	//
	// It includes a buf.yaml and a buf.md file.
	TestDataWithConfiguration = map[string][]byte{
		TestFile1Path:               []byte(`syntax="proto3";`),
		TestFile2Path:               []byte(`syntax="proto3";`),
		"buf.yaml":                  []byte(TestModuleConfiguration),
		TestModuleDocumentationPath: []byte(TestModuleDocumentation),
	}
	// TestDataWithConfigurationAndFallbackDocumentationPath is the data that maps to TestDigestB3WithConfigurationAndFallbackDocumentation.
	//
	// It includes a buf.yaml and a README.md file.
	TestDataWithConfigurationAndFallbackDocumentationPath = map[string][]byte{
		TestFile1Path:                       []byte(`syntax="proto3";`),
		TestFile2Path:                       []byte(`syntax="proto3";`),
		"buf.yaml":                          []byte(TestModuleConfiguration),
		TestModuleFallbackDocumentationPath: []byte(TestModuleDocumentation),
	}
	// TestDataWithLicense is the data that maps to TestDigestB3WithLicense.
	//
	// It includes a LICENSE file.
	TestDataWithLicense = map[string][]byte{
		TestFile1Path: []byte(`syntax="proto3";`),
		"LICENSE":     []byte(TestModuleLicense),
	}
	// TestFile1Path is the path of file1.proto.
	TestFile1Path = "file1.proto"
	// TestFile2Path is the path of file2.proto.
	TestFile2Path = "folder/file2.proto"
	// TestCommit is a valid commit.
	TestCommit string
	// TestModuleReferenceFooBarCommitString is a valid module reference string.
	TestModuleReferenceFooBarCommitString string
	// TestModuleReferenceFooBazCommitString is a valid module reference string.
	TestModuleReferenceFooBazCommitString string
)

Functions

func NewFileInfo

func NewFileInfo(
	t *testing.T,
	path string,
	externalPath string,
	isImport bool,
	moduleIdentity bufmoduleref.ModuleIdentity,
	commit string,
) bufmoduleref.FileInfo

NewFileInfo returns a new FileInfo for testing.

func NewTestModuleReader

func NewTestModuleReader(moduleIdentityStringToModule map[string]bufmodule.Module) bufmodule.ModuleReader

NewTestModuleReader returns a new ModuleReader that will return the mapped module for any ModulePin that has the IdentityString matching the key.

For example:

{"buf.build/foo/bar" -> testModule }

For any ModulePin that has remote "buf.build", owner "foo", and repository "bar", testModule will be returned.

Will typically need to be used in conjunction with WriteTestLockFileToBucket. A bucket will be built with .proto files and a lock file that references the moduleIdentities, and then a test ModuleReader will be created with these Modules.

Example:

bucket := storagemem.NewReadWriteBucket()
err := storage.PutPaths(ctx, bucket, map[string][]data{...}) // put the .proto files
require.NoError(t, err)
err = WriteTestLockFileToBucket(ctx, bucket, "buf.build/acme/bar", "buf.build/acme/baz")
require.NoError(t, err)
fooModule, err := bufmodule.NewModuleForBucket(ctx, bucket)
require.NoError(t, err)
imageBuilder := bufimagebuild.NewBuilder(
  zap.NewNop(),
  bufmoduletesting.NewTestModuleReader(
    map[string]bufmodule.Module{
      "buf.build/acme/bar": barModule,
      "buf.build/acme/baz": bazModule,
    },
  ),
)
err = imageBuilder.Build(ctx, fooModule)

TODO: change this to moduleCommitToModule if we ever introduce a ModuleCommit type to replace ModulePin.

func WriteTestLockFileToBucket

func WriteTestLockFileToBucket(ctx context.Context, writeBucket storage.WriteBucket, moduleIdentityStrings ...string) error

WriteTestLockFileToBucket write a test buf.lock to the given bucket with the given IdentityStrings.

Must be used with a ModuleReader created with NewTestModuleReader. See NewTestModuleReader for example usage.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL