-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for ensuring global variable is updated
- Loading branch information
1 parent
a58e305
commit e089b65
Showing
4 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters