fix e2e init test for windows (#1461)

Signed-off-by: ollevche <ollevche@gmail.com>
This commit is contained in:
Oleksandr Levchenkov 2024-04-04 17:05:17 +03:00 committed by GitHub
parent f75920b609
commit d146acd2e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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])
}