mirror of
https://github.com/opentofu/opentofu.git
synced 2026-05-21 01:26:35 -04:00
Some checks are pending
build / Build for freebsd_386 (push) Waiting to run
build / Build for linux_386 (push) Waiting to run
build / Build for openbsd_386 (push) Waiting to run
build / Build for windows_386 (push) Waiting to run
build / Build for freebsd_amd64 (push) Waiting to run
build / Build for linux_amd64 (push) Waiting to run
build / Build for openbsd_amd64 (push) Waiting to run
build / Build for solaris_amd64 (push) Waiting to run
build / Build for windows_amd64 (push) Waiting to run
build / Build for freebsd_arm (push) Waiting to run
build / Build for linux_arm (push) Waiting to run
build / Build for linux_arm64 (push) Waiting to run
build / Build for darwin_amd64 (push) Waiting to run
build / Build for darwin_arm64 (push) Waiting to run
build / End-to-end Tests for linux_386 (push) Waiting to run
build / End-to-end Tests for windows_386 (push) Waiting to run
build / End-to-end Tests for darwin_amd64 (push) Waiting to run
build / End-to-end Tests for linux_amd64 (push) Waiting to run
build / End-to-end Tests for windows_amd64 (push) Waiting to run
Quick Checks / List files changed for pull request (push) Waiting to run
Quick Checks / Unit tests for linux_386 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for windows_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm (push) Blocked by required conditions
Quick Checks / Unit tests for darwin_arm64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm64 (push) Blocked by required conditions
Quick Checks / Race Tests (push) Blocked by required conditions
Quick Checks / End-to-end Tests (push) Blocked by required conditions
Quick Checks / Code Consistency Checks (push) Blocked by required conditions
Quick Checks / License Checks (push) Waiting to run
Website checks / List files changed for pull request (push) Waiting to run
Website checks / Build (push) Blocked by required conditions
Website checks / Test Installation Instructions (push) Blocked by required conditions
We're currently being intentionally cautious about adding too many tests while these new parts of the system are still evolving and changing a lot, but the execGraphBuilder behavior is hopefully self-contained enough for a small set of basic tests to be more helpful than hurtful. We should extend this test, and add other test cases that involve more complicated interactions between different resource instances of different modes, once we feel that these new codepaths have reached a more mature state where we're more focused on localized maintenance than on broad system design exploration. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
63 lines
2 KiB
Go
63 lines
2 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package planning
|
|
|
|
import (
|
|
"bufio"
|
|
"math"
|
|
"strings"
|
|
)
|
|
|
|
// stripCommonLeadingTabs is a helper for tests that include constant strings
|
|
// for comparison with the result of a [Graph.DebugRepr] call, so that we can
|
|
// write the constant strings indentation to fit well with the surrounding
|
|
// context while ignoring the extra leading tabs that causes.
|
|
//
|
|
// This only considers tabs -- ignoring any other kind of whitespace -- because
|
|
// this is narrowly focused only on test code indentation and we always indent
|
|
// code using tabs.
|
|
func stripCommonLeadingTabs(s string) string {
|
|
// We work in two passes here: first we scan over and find the smallest
|
|
// number of leading tabs that all of the lines of the string have in
|
|
// common, and then we do a second pass to build a new string with that
|
|
// many leading tabs removed from each line.
|
|
|
|
sc := bufio.NewScanner(strings.NewReader(s))
|
|
sc.Split(bufio.ScanLines)
|
|
minTabCount := math.MaxInt
|
|
for sc.Scan() {
|
|
line := sc.Text()
|
|
trimmed := strings.TrimLeft(line, "\t")
|
|
if len(strings.TrimSpace(trimmed)) == 0 {
|
|
continue // empty lines and lines containing only whitespace are ignored
|
|
}
|
|
tabCount := len(line) - len(trimmed)
|
|
if tabCount < minTabCount {
|
|
minTabCount = tabCount
|
|
}
|
|
}
|
|
// (No error check because strings.Reader reads cannot fail)
|
|
|
|
if minTabCount == math.MaxInt {
|
|
// If minTabCount is still the max then that suggests we didn't have
|
|
// any non-empty lines at all, and so there's nothing useful we can do
|
|
// here.
|
|
return ""
|
|
}
|
|
|
|
trimmedPrefix := strings.Repeat("\t", minTabCount)
|
|
var buf strings.Builder
|
|
sc = bufio.NewScanner(strings.NewReader(s))
|
|
sc.Split(bufio.ScanLines)
|
|
for sc.Scan() {
|
|
// No error check because strings.Builder writes cannot fail.
|
|
buf.WriteString(strings.TrimPrefix(sc.Text(), trimmedPrefix))
|
|
buf.WriteByte('\n')
|
|
}
|
|
// (No error check because strings.Reader reads cannot fail)
|
|
|
|
return buf.String()
|
|
}
|