mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
fix e2e init test for windows (#1461)
Signed-off-by: ollevche <ollevche@gmail.com>
This commit is contained in:
parent
f75920b609
commit
d146acd2e6
@ -7,6 +7,7 @@ package e2etest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -465,8 +466,10 @@ func TestInitProviderNotFound(t *testing.T) {
|
||||
t.Fatal("expected error, got success")
|
||||
}
|
||||
|
||||
if !strings.Contains(stdout, `"diagnostic":{"severity":"error","summary":"Failed to query available provider packages","detail":"Could not retrieve the list of available versions for provider hashicorp/nonexist: provider registry.opentofu.org/hashicorp/nonexist was not found in any of the search locations\n\n - `+pluginDir+`"},"type":"diagnostic"}`) {
|
||||
t.Errorf("expected error message is missing from output:\n%s", stdout)
|
||||
escapedPluginDir := escapeStringJSON(pluginDir)
|
||||
|
||||
if !strings.Contains(stdout, `"diagnostic":{"severity":"error","summary":"Failed to query available provider packages","detail":"Could not retrieve the list of available versions for provider hashicorp/nonexist: provider registry.opentofu.org/hashicorp/nonexist was not found in any of the search locations\n\n - `+escapedPluginDir+`"},"type":"diagnostic"}`) {
|
||||
t.Errorf("expected error message is missing from output (pluginDir = '%s'):\n%s", escapedPluginDir, stdout)
|
||||
}
|
||||
})
|
||||
|
||||
@ -522,3 +525,24 @@ func TestInitProviderNotFound(t *testing.T) {
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
func escapeStringJSON(v string) string {
|
||||
b := &strings.Builder{}
|
||||
|
||||
enc := json.NewEncoder(b)
|
||||
|
||||
enc.SetEscapeHTML(false)
|
||||
|
||||
if err := enc.Encode(v); err != nil {
|
||||
panic("failed to escapeStringJSON: " + v)
|
||||
}
|
||||
|
||||
marshaledV := b.String()
|
||||
|
||||
// shouldn't happen
|
||||
if len(marshaledV) < 2 {
|
||||
return string(marshaledV)
|
||||
}
|
||||
|
||||
return string(marshaledV[1 : len(marshaledV)-2])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user