Implement new stackit_image resource and datasource (#609)

* feat: Implement image resource and datasource

* feat: Add remaining config options

* feat: Make protected field only computed

* feat: Update dependency to use IaaS beta API

* fix: Minor fix in acc test

---------

Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com>
This commit is contained in:
João Palet 2025-01-09 11:57:25 +00:00 committed by GitHub
parent 7fcebacb21
commit 700bdc90d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 2212 additions and 4 deletions

View file

@ -0,0 +1 @@
I am a test file

View file

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net"
"os"
"regexp"
"strings"
"time"
@ -272,3 +273,21 @@ func Rrule() *Validator {
},
}
}
func FileExists() *Validator {
description := "file must exist"
return &Validator{
description: description,
validate: func(_ context.Context, req validator.StringRequest, resp *validator.StringResponse) {
_, err := os.Stat(req.ConfigValue.ValueString())
if err != nil {
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
req.Path,
description,
req.ConfigValue.ValueString(),
))
}
},
}
}

View file

@ -682,3 +682,42 @@ func TestRrule(t *testing.T) {
})
}
}
func TestFileExists(t *testing.T) {
tests := []struct {
description string
input string
isValid bool
}{
{
"ok",
"testdata/file.txt",
true,
},
{
"not ok",
"testdata/non-existing-file.txt",
false,
},
{
"empty",
"",
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
r := validator.StringResponse{}
FileExists().ValidateString(context.Background(), validator.StringRequest{
ConfigValue: types.StringValue(tt.input),
}, &r)
if !tt.isValid && !r.Diagnostics.HasError() {
t.Fatalf("Should have failed")
}
if tt.isValid && r.Diagnostics.HasError() {
t.Fatalf("Should not have failed: %v", r.Diagnostics.Errors())
}
})
}
}