Skip to content

Commit

Permalink
Merge pull request #72 from bobh66/handle_no_resources
Browse files Browse the repository at this point in the history
Include outputs in test for ResourceExists  (#71)
  • Loading branch information
bobh66 authored Jul 7, 2022
2 parents 63bb84b + 57b90c1 commit 158879a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/controller/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
cr.Status.AtProvider = generateWorkspaceObservation(op)

return managed.ExternalObservation{
ResourceExists: len(r) > 0,
ResourceExists: len(r)+len(op) > 0,
ResourceUpToDate: !differs,
ResourceLateInitialized: false,
ConnectionDetails: op2cd(op),
Expand Down
41 changes: 41 additions & 0 deletions internal/controller/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,47 @@ func TestObserve(t *testing.T) {
},
},
},
"WorkspaceExistsOnlyOutputs": {
reason: "A workspace with only outputs and no resources should set ResourceExists to true",
fields: fields{
tf: &MockTf{
MockDiff: func(ctx context.Context, o ...terraform.Option) (bool, error) { return false, nil },
MockResources: func(ctx context.Context) ([]string, error) {
return nil, nil
},
MockOutputs: func(ctx context.Context) ([]terraform.Output, error) {
return []terraform.Output{
{Name: "string", Type: terraform.OutputTypeString, Sensitive: false},
{Name: "object", Type: terraform.OutputTypeObject, Sensitive: true},
}, nil
},
},
},
args: args{
mg: &v1alpha1.Workspace{
Spec: v1alpha1.WorkspaceSpec{
ForProvider: v1alpha1.WorkspaceParameters{
PlanArgs: []string{"-refresh=false"},
},
},
},
},
want: want{
o: managed.ExternalObservation{
ResourceExists: true,
ResourceUpToDate: true,
ConnectionDetails: managed.ConnectionDetails{
"string": {},
"object": []byte("null"), // Because we JSON decode the the value, which is interface{}{}
},
},
wo: v1alpha1.WorkspaceObservation{
Outputs: map[string]string{
"string": "",
},
},
},
},
}

for name, tc := range cases {
Expand Down

0 comments on commit 158879a

Please sign in to comment.