terraform/internal/configs/source_bundle_parser_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
Go
Raw Permalink Normal View History

2026-01-29 12:25:37 -05:00
// Copyright IBM Corp. 2014, 2026
// SPDX-License-Identifier: BUSL-1.1
package configs
import (
"path/filepath"
"testing"
"github.com/hashicorp/go-slug/sourceaddrs"
"github.com/hashicorp/go-slug/sourcebundle"
)
// TestSourceBundleParser_LoadConfigDir_WithRelativePath tests that when
// LocalPathForSource returns a relative path, LoadConfigDir correctly uses
// it as-is without attempting to convert it.
func TestSourceBundleParser_LoadConfigDir_WithRelativePath(t *testing.T) {
// Use the basics-bundle from stacks testdata which has a component with has a relative source.
bundlePath := "../stacks/stackconfig/testdata/basics-bundle"
bundle, err := sourcebundle.OpenDir(bundlePath)
2026-01-29 12:25:37 -05:00
if err != nil {
t.Fatalf("failed to open source bundle: %s", err)
}
source := sourceaddrs.MustParseSource("../stacks/stackconfig/testdata/basics-bundle").(sourceaddrs.FinalSource)
2026-01-29 12:25:37 -05:00
// Create a SourceBundleParser and load the config directory.
parser := NewSourceBundleParser(bundle)
2026-01-29 12:25:37 -05:00
mod, diags := parser.LoadConfigDir(source)
if diags.HasErrors() {
t.Fatalf("unexpected errors: %s", diags.Error())
}
if mod == nil {
t.Fatal("expected non-nil module")
}
// Verify that the SourceDir is set and that it's a relative path.
if mod.SourceDir == "" {
t.Error("expected SourceDir to be set, but it was empty")
}
2026-01-29 12:25:37 -05:00
if filepath.IsAbs(mod.SourceDir) {
t.Errorf("expected SourceDir to be relative, but got absolute path: %s", mod.SourceDir)
}
}