diff --git a/tfprotov5/tf5server/proto_version_test.go b/tfprotov5/tf5server/proto_version_test.go new file mode 100644 index 000000000..85974264f --- /dev/null +++ b/tfprotov5/tf5server/proto_version_test.go @@ -0,0 +1,50 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package tf5server + +import ( + "bufio" + "os" + "regexp" + "testing" +) + +// MAINTAINER NOTE: This test is a best effort for ensuring that the protocol version variables in the tf5server package +// stay in sync with the actual protocol file. +func Test_EnsureVersionConstantMatchesProtoFile(t *testing.T) { + t.Parallel() + + file, err := os.Open("../internal/tfplugin5/tfplugin5.proto") + if err != nil { + t.Fatalf("error opening proto file: %s", err) + } + defer file.Close() + + protoFileComment := regexp.MustCompile(`(?:Terraform Plugin RPC protocol version )(\d+.\d+)+`) + + var expectedProtocolVersion string + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + matches := protoFileComment.FindStringSubmatch(line) + + if len(matches) > 1 { + expectedProtocolVersion = matches[1] + break + } + } + + if err := scanner.Err(); err != nil { + t.Fatalf("error scanning proto file: %s", err) + } + + if expectedProtocolVersion == "" { + t.Fatalf("couldn't find version comment in proto file: %s", err) + } + + if protocolVersion != expectedProtocolVersion { + t.Errorf("protocol version Go variable is different from proto file - expected: %s, got: %s\n", expectedProtocolVersion, protocolVersion) + t.Log("MAINTAINER NOTE: Update tf5server.protocolVersionMajor and tf5server.protocolVersionMinor to match the proto file.") + } +} diff --git a/tfprotov5/tf5server/server.go b/tfprotov5/tf5server/server.go index d6c0daacf..c2fda481b 100644 --- a/tfprotov5/tf5server/server.go +++ b/tfprotov5/tf5server/server.go @@ -49,7 +49,7 @@ const ( // // In the future, it may be possible to include this information directly // in the protocol buffers rather than recreating a constant here. - protocolVersionMinor uint = 4 + protocolVersionMinor uint = 6 ) // protocolVersion represents the combined major and minor version numbers of diff --git a/tfprotov6/tf6server/proto_version_test.go b/tfprotov6/tf6server/proto_version_test.go new file mode 100644 index 000000000..0b091a9ca --- /dev/null +++ b/tfprotov6/tf6server/proto_version_test.go @@ -0,0 +1,50 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package tf6server + +import ( + "bufio" + "os" + "regexp" + "testing" +) + +// MAINTAINER NOTE: This test is a best effort for ensuring that the protocol version variables in the tf6server package +// stay in sync with the actual protocol file. +func Test_EnsureVersionConstantMatchesProtoFile(t *testing.T) { + t.Parallel() + + file, err := os.Open("../internal/tfplugin6/tfplugin6.proto") + if err != nil { + t.Fatalf("error opening proto file: %s", err) + } + defer file.Close() + + protoFileComment := regexp.MustCompile(`(?:Terraform Plugin RPC protocol version )(\d+.\d+)+`) + + var expectedProtocolVersion string + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + matches := protoFileComment.FindStringSubmatch(line) + + if len(matches) > 1 { + expectedProtocolVersion = matches[1] + break + } + } + + if err := scanner.Err(); err != nil { + t.Fatalf("error scanning proto file: %s", err) + } + + if expectedProtocolVersion == "" { + t.Fatalf("couldn't find version comment in proto file: %s", err) + } + + if protocolVersion != expectedProtocolVersion { + t.Errorf("protocol version Go variable is different from proto file - expected: %s, got: %s", expectedProtocolVersion, protocolVersion) + t.Log("MAINTAINER NOTE: Update tf6server.protocolVersionMajor and tf6server.protocolVersionMinor to match the proto file.") + } +} diff --git a/tfprotov6/tf6server/server.go b/tfprotov6/tf6server/server.go index ce8f6f57e..674cec58f 100644 --- a/tfprotov6/tf6server/server.go +++ b/tfprotov6/tf6server/server.go @@ -49,7 +49,7 @@ const ( // // In the future, it may be possible to include this information directly // in the protocol buffers rather than recreating a constant here. - protocolVersionMinor uint = 4 + protocolVersionMinor uint = 6 ) // protocolVersion represents the combined major and minor version numbers of