feat: implement stackit git instances (#791)
* feat: implement stackit git instances * review changes
This commit is contained in:
parent
c7c64a5806
commit
cf7a7d154e
16 changed files with 937 additions and 96 deletions
79
stackit/internal/services/git/instance/resource_test.go
Normal file
79
stackit/internal/services/git/instance/resource_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package instance
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/git"
|
||||
)
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
input *git.Instance
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&git.Instance{
|
||||
Created: nil,
|
||||
Id: utils.Ptr("id"),
|
||||
Name: utils.Ptr("foo"),
|
||||
Url: utils.Ptr("https://foo.com"),
|
||||
Version: utils.Ptr("v0.0.1"),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,id"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
InstanceId: types.StringValue("id"),
|
||||
Name: types.StringValue("foo"),
|
||||
Url: types.StringValue("https://foo.com"),
|
||||
Version: types.StringValue("v0.0.1"),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"nil_response",
|
||||
nil,
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"nil_response_2",
|
||||
&git.Instance{},
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_id",
|
||||
&git.Instance{
|
||||
Name: utils.Ptr("foo"),
|
||||
},
|
||||
Model{},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
state := &Model{
|
||||
ProjectId: tt.expected.ProjectId,
|
||||
}
|
||||
err := mapFields(tt.input, state)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
if tt.isValid && err != nil {
|
||||
t.Fatalf("Should not have failed: %v", err)
|
||||
}
|
||||
if tt.isValid {
|
||||
diff := cmp.Diff(state, &tt.expected)
|
||||
if diff != "" {
|
||||
t.Fatalf("Data does not match: %s", diff)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue